1。结合前面2篇文章
对于用VB2008.NET的新用户,可能看不到DataGrid,也不知道如何加入到项目中来。(虽然我前面已经详细截图,无奈于仍然有人不解。)
那么不要紧,直接用DataGridView就可以了。
下面的步骤为你一一解答,让DataGridView连接SQL Server2005的数据库。
结合图片讲解。
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1中
Dim objconnection As New SqlConnection("server=YW;database=database;Integrated Security=True")
Dim objdataadapter As New SqlDataAdapter("select Sno,Sname,Ssex,Sbirthday,Sid,Scollege,Sclass,Sindate from studentinfo", objconnection)
Dim objdataset As DataSet
Dim objdataview As DataView
Dim objcurrencymanager As CurrencyManager
Private Sub filldatasetandview()
objdataset = New DataSet()
objdataadapter.Fill(objdataset, "studentinfo")
objdataview = New DataView(objdataset.Tables("studentinfo"))
objcurrencymanager = CType(Me.BindingContext(objdataview), CurrencyManager)
End Sub
Private Sub Form1_Load 中
在前面两篇的基础上加入如下代码:
DataGridView2.DataSource = dts.DefaultView
filldatasetandview()
DataGridView1.DataSource = objdataview
DataGridView2是连接的ACCESS数据库。
DataGridView1是连接的SQL Server2005的数据库。
2。运行后的结果图