VB 怎么把按条件输入的内容在数据库中查询后,显示在下面的表中,求代码

2025-01-18 21:01:59
推荐回答(1个)
回答1:

'Ctrl+t找Microsoft DataGrid Control....
'菜单"工程"->"引用" 找 Microsoft ActiveX Data Object....
Dim cn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim SqlStr As String
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Mode=ReadWrite"
SqlStr = "Select * From 社员 where 姓名 = '" & Text1.Text & "'"
rst.CursorLocation = adUseClient
rst.Open SqlStr, cn, adOpenDynamic, adLockOptimistic, adCmdText '打开记录集
Set DataGrid1.DataSource = rst '给DataGrid修改数据源