VB中查询Access数据库让结果显示在Datagridview中
DimcnnAsNewADODB.ConnectionDimrsAsNewADODB.Recordsetcnn.ConnectionString="Provider=Mi...
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\qn\My Documents\Visual Studio 2005\Projects\vbexercise\vbexercise\Jet 4.0.mdb"
cnn.CursorLocation = adUseClient
cnn.Open()
rs.Open("Select A.社员CD,A.社员カナ,A.社员名,B.部门名 From 社员 A,部门 B where b.部门cd = a.部门cd", cnn, 3, 3)
Me.DGV社员Show.DataSource = rs
Me.DGV社员Show.Refresh()
为什么就是显示不了数据呢?? 展开
Dim rs As New ADODB.Recordset
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\qn\My Documents\Visual Studio 2005\Projects\vbexercise\vbexercise\Jet 4.0.mdb"
cnn.CursorLocation = adUseClient
cnn.Open()
rs.Open("Select A.社员CD,A.社员カナ,A.社员名,B.部门名 From 社员 A,部门 B where b.部门cd = a.部门cd", cnn, 3, 3)
Me.DGV社员Show.DataSource = rs
Me.DGV社员Show.Refresh()
为什么就是显示不了数据呢?? 展开
展开全部
Private myCon As New OleDbConnection
Private mycmd As New OleDbCommand
Private myada As New OleDbDataAdapter
myCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CurDir() & "\Jet 4.0.mdb"
myCon.Open()
mycmd.CommandText ="Select A.社员CD,A.社员カナ,A.社员名,B.部门名 From 社员 A,部门 B where b.部门cd = a.部门cd"
mycmd.Connection = myCon
myada.SelectCommand = mycmd
myds.Clear()
myada.Fill(myds, "表名")
Me.DGV社员Show.DataSource = myada
Me.DGV社员Show.Refresh()
我是做C# 用这个VB 很是不习惯,代码条理不清晰,但总的思想是这样的,你自己稍为看下。给点建议:
在控件命名时不要使用中文
数据库尽量不要使用绝对路径OVER
Private mycmd As New OleDbCommand
Private myada As New OleDbDataAdapter
myCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CurDir() & "\Jet 4.0.mdb"
myCon.Open()
mycmd.CommandText ="Select A.社员CD,A.社员カナ,A.社员名,B.部门名 From 社员 A,部门 B where b.部门cd = a.部门cd"
mycmd.Connection = myCon
myada.SelectCommand = mycmd
myds.Clear()
myada.Fill(myds, "表名")
Me.DGV社员Show.DataSource = myada
Me.DGV社员Show.Refresh()
我是做C# 用这个VB 很是不习惯,代码条理不清晰,但总的思想是这样的,你自己稍为看下。给点建议:
在控件命名时不要使用中文
数据库尽量不要使用绝对路径OVER
展开全部
添加一个adodc控件
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\qn\My Documents\Visual Studio 2005\Projects\vbexercise\vbexercise\Jet 4.0.mdb"
Adodc1.ConnectionString = CnnStr
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select A.社员CD,A.社员カナ,A.社员名,B.部门名 From 社员 A,部门 B where b.部门cd = a.部门cd"
adodc1.refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Refresh
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\qn\My Documents\Visual Studio 2005\Projects\vbexercise\vbexercise\Jet 4.0.mdb"
Adodc1.ConnectionString = CnnStr
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select A.社员CD,A.社员カナ,A.社员名,B.部门名 From 社员 A,部门 B where b.部门cd = a.部门cd"
adodc1.refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Refresh
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |