不使用ADO控件,如何使DataGrid显示一个数据库文件的内容,有其它控件可以显示一个数据库文件的内容也可以,前提是不要先使用其它的控件
http://bbs.bc-cn.net/viewthread.php?tid=85265&extra=&page=100#
看8樓````
[CODE]Option Explicit
Dim conn As ADODB.Connection
Private Sub Form_Load()
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & App.Path & "\imformation.mdb"
conn.Open
Dim RST As ADODB.Recordset
Set RST = New ADODB.Recordset
RST.Open "select * from user", conn, 2, 2
Set DataGrid1.DataSource = RST
End Sub[/CODE]
这是代码,看看哪个地方要改
我之前已经说过了..user可能是数据库的关键字..为表安全...请用[]来括起来...
Option Explicit
Private dbConn As ADODB.Connection
Private Rst As ADODB.Recordset
Private Sub Form_Load()
Set dbConn = New ADODB.Connection
dbConn.Open "Provider=Microsoft.Jet.OleDb.4.0;Data Source=D:\mdb\Northwind.mdb"
Set Rst = New ADODB.Recordset
Rst.CursorLocation = adUseClient
Rst.Open "select * from [orders]", dbConn, adOpenKeyset, adLockPessimistic, adCmdText
Set DataGrid1.DataSource = Rst
End Sub