您的位置首页百科快答

在vb中如何只用datagrid控件连接数据库并显示出来

在vb中如何只用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我帮你整理了以下,这样好看一些