如何实现VB中用DataGrid控件显示数据? 10
PrivateSubForm_Load()Adodc.ConnectionString="provider=Microsoft.jet.OLEDB.4.0;Persist...
Private Sub Form_Load()
Adodc.ConnectionString = "provider=Microsoft.jet.OLEDB.4.0;Persist security info= False; Data source= 图书馆查询管理系统.mdb"
Adodc.CursorLocation = adUseClient
Adodc.CursorType = adOpenKeyset
Adodc.LockType = adLockOptimistic
Adodc.CommandType = adCmdText
Adodc.RecordSource = "select * from readerInfo"
Adodc.Refresh
'设置DataGrid显示资料表里的资料
Set DataGrid.DataSource = Adodc
DataGrid.Refresh
End Sub
高手看看哪里出现错误了
高手帮助请加我QQ:372332576
谢谢了 展开
Adodc.ConnectionString = "provider=Microsoft.jet.OLEDB.4.0;Persist security info= False; Data source= 图书馆查询管理系统.mdb"
Adodc.CursorLocation = adUseClient
Adodc.CursorType = adOpenKeyset
Adodc.LockType = adLockOptimistic
Adodc.CommandType = adCmdText
Adodc.RecordSource = "select * from readerInfo"
Adodc.Refresh
'设置DataGrid显示资料表里的资料
Set DataGrid.DataSource = Adodc
DataGrid.Refresh
End Sub
高手看看哪里出现错误了
高手帮助请加我QQ:372332576
谢谢了 展开
2015-08-09
展开全部
VB利用DataGrid控件显示数据库中数据信息,DataGrid在数据库数据显示的时候非常重要,它在用户操作舒适度及数据排列方面有独到之处,对于Vb数据库编程的用户来说,掌握DataGrid的使用是至关重要的事情。
参考实例如下:
Public cnn As adodb.Connection
Public rst As adodb.Recordset
Public Sub setdb()
Set cnn = New adodb.Connection
cnn.Provider = "Microsoft.Jet.OLEDB.4.O"
cnn.ConnectionString = "Data Source=" & App.Path & "\personal.mdb;"
cnn.CursorLocation = adUseClient
cnn.Open
End Sub
Private Sub Form_Load()
On Error Resume Next
Dim Strsql As String
setdb
Set DataGrid1.DataSource = Nothing
Strsql = "select * from 备忘录 order by 编号"
Set rst = cnn.Execute(Strsql)
If Err Then
MsgBox "读取数据失败"
Exit Sub
End If
If rst.EOF Then
Set DataGrid1.DataSource = Nothing
Else
Set DataGrid1.DataSource = rst
End If
End Sub
参考实例如下:
Public cnn As adodb.Connection
Public rst As adodb.Recordset
Public Sub setdb()
Set cnn = New adodb.Connection
cnn.Provider = "Microsoft.Jet.OLEDB.4.O"
cnn.ConnectionString = "Data Source=" & App.Path & "\personal.mdb;"
cnn.CursorLocation = adUseClient
cnn.Open
End Sub
Private Sub Form_Load()
On Error Resume Next
Dim Strsql As String
setdb
Set DataGrid1.DataSource = Nothing
Strsql = "select * from 备忘录 order by 编号"
Set rst = cnn.Execute(Strsql)
If Err Then
MsgBox "读取数据失败"
Exit Sub
End If
If rst.EOF Then
Set DataGrid1.DataSource = Nothing
Else
Set DataGrid1.DataSource = rst
End If
End Sub
展开全部
Dim cn As New ADODB.Connection
Dim Adodc As New ADODB.Recordset
Private Sub Form_Load()
cn.Open = "provider=Microsoft.jet.OLEDB.4.0;Persist security info= False; Data source= " & App.Path & "\ 图书馆查询管理系统.mdb"
Adodc.CursorLocation = adUseClient
Adodc.Open "select * from readerinfo", cn, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = Adodc
End Sub
试试 ,,不行的话,HI我
Dim Adodc As New ADODB.Recordset
Private Sub Form_Load()
cn.Open = "provider=Microsoft.jet.OLEDB.4.0;Persist security info= False; Data source= " & App.Path & "\ 图书馆查询管理系统.mdb"
Adodc.CursorLocation = adUseClient
Adodc.Open "select * from readerinfo", cn, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = Adodc
End Sub
试试 ,,不行的话,HI我
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Set DataGrid.DataSource = Adodc
将这句的“DataGrid”换成DataGrid控件的名称
将这句的“DataGrid”换成DataGrid控件的名称
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
数据库地址错了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询