vb读取access数据

2024-11-20 18:23:50
推荐回答(1个)
回答1:

Private Sub Command2_Click()
If Text3 = "" Then
MsgBox "请输入查询内容!"
Text3.SetFocus
Else
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\1.mdb"
rs.CursorLocation = adUseClient
rs.Open "select * from [表1] where 姓名='" & Text3.Text & "'", conn
If rs.EOF Then
MsgBox "查找内容不存在,请重新输入!"
Text3.SetFocus
Else
On Error Resume Next
Text4.Text = rs.Fields(2) '表内第0列为编号,第1列姓名,第2列为分数
rs.Close
conn.Close
End If
End If
End Sub