50分求解,在VB6.0中查询Access数据库多字段并加条件查询,?

在VB6.0中查询Access数据库多字段并加条件查询,代码如下:
Private Sub Command1_Click()
strfilename = "E:\XXZL\tEST.mdb"
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.CursorLocation = adUseClient
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & strfilename & ";Persist Security Info=False"
cn.Open ConnectionString
StrSQL = "select DD,BB,CC,AA from RES where AA= '" & Text1.Text & "'"
rs.Open StrSQL, cn, adOpenKeyset, adLockOptimistic
Set DataGrid1.DataSource = rs
End Sub
------------------------------
Access数据库如图所示,有字段AA,BB,CC,DD
运行上面代码比如我要查询值ab1,表里的所有ab1查询出来,但是我还想加一个条件就是,把表里的数值为ab1,同时在字段DD中的值为1的,(意思是,把表里值DD字段为1的同时又要是AA字段值为ab1同时查询出来),友友们帮帮忙,送上50分.
问题已解决小弟在此感谢 bron1984 兄弟
Private Sub Command1_Click()
strfilename = "E:\XXZL\tEST.mdb"
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.CursorLocation = adUseClient
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & strfilename & ";Persist Security Info=False"
cn.Open ConnectionString
StrSQL = "select DD,BB,CC,AA from RES where AA= '" & Text1.Text & "' and DD='1'"
rs.Open StrSQL, cn, adOpenKeyset, adLockOptimistic
Set DataGrid1.DataSource = rs
End Sub

ADODC控件要设置两个属性
ConnectionString="连接到数据库的字符串",点击边上的下拉按钮就能浏览到你要的数据库,也可以直接在程序中设置。
RecordSource=“要打开的数据表或者查询”
然后TextBox要设置两个属性
DataSource=上面设置的那个数据控件,比如ADODC1,你把ADODC控件添加到Form中的时候,在这个属性里面就能选择
DataField=你要在Textbox中显示的字段,如果你在Adodc1中设置好正确的连接,这个属性能让你选择需要显示的字段
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-01-06
D如果是数字型字段:
StrSQL = "select DD,BB,CC,AA from RES where AA= '" & Text1.Text & "' and DD=1"

D如果是字符型字段:
StrSQL = "select DD,BB,CC,AA from RES where AA= '" & Text1.Text & "' and DD='1'"
第2个回答  2012-01-06
StrSQL = "select DD,BB,CC,AA from RES where AA= '" & Text1.Text & "' and DD=1 and AA = 'ab1'"
第3个回答  2012-01-06
将StrSQL =。。。这句改为:如果DD为数值则:StrSQL = "select DD,BB,CC,AA from RES where AA= '" & Text1.Text & "' And DD=1"
如果DD为文本则 StrSQL = "select DD,BB,CC,AA from RES where AA= '" & Text1.Text & "' And DD=‘1’"
第4个回答  2012-01-06
高难度了, 我不会。,