Private Sub Command1_Click ()
Dim Cn As New ADODB. Connection
Dim Rst As New ADODB. You
Dim SqlStr As String
Cn. The Open ". The Provider=Microsoft Jet. The OLEDB. 4.0; Data Source="& amp; App. The Path & amp; "\ db2. MDB; Persist Security Info=False "
SqlStr="Select * From table 1"
Rst. CursorLocation=adUseClient
Rst. Open SqlStr, Cn, adOpenDynamic adLockOptimistic, adCmdText 'Open recordset
Set DataGrid1. The DataSource to DataGrid modify data source=Rst '
End Sub
Private Sub Command2_Click ()
Dim Cn As New ADODB. Connection
Dim Rst As New ADODB. You
Dim SqlStr As String
Cn. The Open ". The Provider=Microsoft Jet. The OLEDB. 4.0; Data Source="& amp; App. The Path & amp; "\ db2. MDB; Persist Security Info=False "
SqlStr="Select * From table 1 where name='" & amp; Text2. Text & amp; "'
"Rst. CursorLocation=adUseClient
Rst. Open SqlStr, Cn, adOpenDynamic adLockOptimistic, adCmdText 'Open recordset
Set DataGrid1. The DataSource to DataGrid modify data source=Rst '
End Sub
CodePudding user response:
SqlStr="Select * From table 1 where name='" & amp; Text2. Text & amp; "'"
Put including the names of all the fields in a combobox,
The code is amended as:
SqlStr="Select * From table 1 where" & amp; Combo1. Text & amp;"='" & amp; Text2. Text & amp; "'"