在vb中如何只用datagrid控件连接数据库并显示出来 要完整的代码 5
下面是我写的,表里有内容为什么说读取数据失败PubliccnnAsadodb.ConnectionPublicrstAsadodb.RecordsetPublicSubs...
下面是我写的,表里有内容为什么说读取数据失败
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 展开
2个回答
展开全部
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
我帮你整理了以下,这样好看一些
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询