查询语句 Data1.RecordSource = "Select * From stocks Where sqlName = '" &thisName & " ' "
其中sqlName 是从text获取的值
你修改下面的例子尝试一下:
Private Sub Command1_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim ss As String
Dim qs As String
ss = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\p\桌面\a.mdb;Persist Security Info=False"
conn.Open ss
qs = "select * from a where sqlName=" & Val(thisName)
rs.Open qs, conn, 1, 3, -1
Label1.Caption = rs.Fields(1) ’显示字段1
Label2.Caption = rs.Fields(2) ‘显示字段2
’.......类推
rs.Close
conn.Close
End Sub
****注意通过了VB6.0测试.控件(command1,label1,label2,adodc1,text1).
数据库路径最好用相对路径.否则移置性不好.相对路径可用 app.path,表示应用程序的路径,你把a.mdb放在你编写程序的相同路径时.连接库代码可写成:ss = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &app.path & "\a.mdb;Persist Security Info=False"
数据表的结构有姓名字段才行
比方说,表名为UserInfo,字段名为UserName
SQL语句可以这么写:Select * From UserInfo Where UserInfo.UserName='张三'