vb access输入某字段内容查询其他信息

2024-12-28 10:39:26
推荐回答(3个)
回答1:

'引用microsoft activex data objects 2.x library

'添加三个TEXT,一个COMMAND

方法一:

Private Sub Command1_Click()
Dim Cnn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Dim s As String
s = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\Ballsky\桌面\进货单.accdb" '换成你自己的AC接连字符串
Cnn.Open s
Rs.CursorLocation = adUseClient
Rs.Open "这里换成你的数据库表名称", Cnn, 3, 3
Do While Not Rs.EOF
If Text1.Text = Rs.Fields(0) Then
Text2.Text = Rs.Fields(1)
Text3.Text = Rs.Fields(2)
End If
Rs.MoveNext
Loop
Rs.Close
Cnn.Close
End Sub

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
方法二:

Private Sub Command1_Click()
Dim Cnn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Dim S As String, Sing As String
S = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\Ballsky\桌面\进货单.accdb" '换成你自己的AC接连字符串
Cnn.Open S
Rs.CursorLocation = adUseClient
Sing = "select * from 你的表名称 where UName ='" & Text1.Text & "'"
Rs.Open Sing, Cnn, 3, 3
On Error Resume Next
Text1.Text = Rs.Fields(0)
Text2.Text = Rs.Fields(1)
Text3.Text = Rs.Fields(2)
Rs.Close
Cnn.Close
End Sub

回答2:

我都是引用microsoft activex data objects 2.5 library
连接数据库,其他的方法不太懂。

回答3:

ballsky 正解,呵呵。