local_sql = "select 姓名 from dushuju where " & " dushuju.单元 ='" & datacombo2.text & "' and dushuju.房号='" & datacombo3.text & "'"最主要你忘了'号。 对于字符型的查询,条件需要'和'括起来。
呵呵,你只写了查询的字符串 而并没有执行查询 如果用adors.open "select 姓名 from dushuju where dushuju.搂号 =datacombo1.text and dushuju.单元 =datacombo2.text and dushuju.房号 =datacombo3.text",conn,3,1
对于数据库的查询,需要将sql语句使用command对象或者是recordset对象来实现查询。
local_sql = "select 姓名 from dushuju where dushuju.搂号 =" & datacombo1.text & " and dushuju.单元 =" & datacombo2.text & "and dushuju.房号 =" & datacombo3.text
local_sql = "select 姓名 from dushuju where dushuju.搂号 ='" & datacombo1.text & "' and dushuju.单元 ='" & datacombo2.text & "'and dushuju.房号 ='" & datacombo3.text &"'
Private Sub Command1_Click() Dim local_sql As String Dim louhao As String Dim danyuan As Integer Dim fangjian As Integer louhao = DataCombo1.text danyuan = DataCombo2.text fangjian = DataCombo3.text local_sql = "select 姓名 from dushuju where dushuju.楼号=" & louhao & " and dushuju.单元 =" & danyuan & " and dushuju.房号 =" & fangjian set conn=new adodb.connection conn.open "......" set rs=new adodb.recordset rs.open local_sql,conn,3,3 while not rs.eof Label6.Caption = Label6.caption & rs.fields("姓名") rs.movenext wend End Sub
这样,在你的最后一句处加上: dim cnn as new adodb.connection,rs as new adodb.recordsetcnn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = yourdb.mdb;Persist Security Info=False" set rs = cnn.execute(local_sql) Label6.Caption = rs!姓名
对于字符型的查询,条件需要'和'括起来。
而并没有执行查询
如果用adors.open "select 姓名 from dushuju where dushuju.搂号 =datacombo1.text and dushuju.单元 =datacombo2.text and dushuju.房号 =datacombo3.text",conn,3,1
Dim local_sql As String
Dim louhao As String
Dim danyuan As Integer
Dim fangjian As Integer
louhao = DataCombo1.text
danyuan = DataCombo2.text
fangjian = DataCombo3.text
local_sql = "select 姓名 from dushuju where dushuju.楼号=" & louhao & " and dushuju.单元 =" & danyuan & " and dushuju.房号 =" & fangjian
set conn=new adodb.connection
conn.open "......"
set rs=new adodb.recordset
rs.open local_sql,conn,3,3
while not rs.eof
Label6.Caption = Label6.caption & rs.fields("姓名")
rs.movenext
wend
End Sub
dim cnn as new adodb.connection,rs as new adodb.recordsetcnn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = yourdb.mdb;Persist Security Info=False"
set rs = cnn.execute(local_sql) Label6.Caption = rs!姓名