'引用microsoft activex data object 2.x library Option Explicit Private conn As ADODB.Connection Private rs As ADODB.RecordsetPrivate Sub Command1_Click()Dim apppath As String Dim dbfilename As String Dim ConnectString As String Dim i As Integer Set conn = New ADODB.Connection If Right(App.Path, 1) = "\" Then apppath = App.Path Else apppath = App.Path & "\" End If dbfilename = apppath & "order.mdb" ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfilename & ";Persist Security Info=False;" conn.Open ConnectString conn.CursorLocation = adUseClientSet rs = New ADODB.Recordset rs.Open "select * from orders where id="& val(text1.text), conn, adOpenDynamic, adLockPessimistic If rs.EOF Then Exit Sub End IfSet DataGrid1.DataSource = rs End Sub
Option Explicit
Private conn As ADODB.Connection
Private rs As ADODB.RecordsetPrivate Sub Command1_Click()Dim apppath As String
Dim dbfilename As String
Dim ConnectString As String
Dim i As Integer
Set conn = New ADODB.Connection
If Right(App.Path, 1) = "\" Then
apppath = App.Path
Else
apppath = App.Path & "\"
End If
dbfilename = apppath & "order.mdb"
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfilename & ";Persist Security Info=False;"
conn.Open ConnectString
conn.CursorLocation = adUseClientSet rs = New ADODB.Recordset
rs.Open "select * from orders where id="& val(text1.text), conn, adOpenDynamic, adLockPessimistic
If rs.EOF Then
Exit Sub
End IfSet DataGrid1.DataSource = rs
End Sub