各位大虾好!
我用ADODC控件查询,怎么报错呢?写法如下
adodc1.recordset.find "字段1='"& aa &"' and 字段2='"& aa &"'"
这样写有错吗?
如adodc1.recordset.find "字段1='"& aa &"'" 写可以查询,为什么联两个字段以上用find不能查呢?我错在哪??

解决方案 »

  1.   

    错就错在你要分开写查询的字段,and两边的字段要用引号分开的像这样写
    strsearch = Trim(Text1.Text)
    strtable = "目录"
    strFilter = " " & stroption & " like " & " '%" & strsearch & "%' "
    strgoods = "*" '"内容"strSQL = "select " & strgoods & " from " & strtable & " where " & stroption & " like '%" & strsearch & "%'"
      

  2.   

    c.CommandText = "select * from 其他 where " & Trim(IIf(Text1.Text = "", "'=ALL'", "姓名 like " & "'%" & Text1.Text & "%'")) & "and " & Trim(IIf(Combo1.Text = "", "'=ALL'", "学号='" & Trim(Combo1.List(Combo1.ListIndex)) & "'")) & "and " & Trim(IIf(Combo2.Text = "", "'=ALL'", "性别='" & Trim(Combo2.List(Combo2.ListIndex)) & "'")) & " and " & Trim(IIf(Combo3.Text = "", "'=ALL'", "计算机水平='" & Trim(Combo3.List(Combo3.ListIndex)) & "'")) & " and " & Trim(IIf(Combo4.Text = "", "'=ALL'", "英语水平='" & Trim(Combo4.List(Combo4.ListIndex)) & "'")) & " and " & Trim(IIf(Combo5.Text = "", "'=ALL'", "就业意愿='" & Trim(Combo5.List(Combo5.ListIndex)) & "'")) & " and " & Trim(IIf(Combo6.Text = "", "'=ALL'", "就业方向='" & Trim(Combo6.List(Combo6.ListIndex)) & "'")) & " and " & Trim(IIf(Combo7.Text = "", "'=ALL'", "是否签约='" & Trim(Combo7.List(Combo7.ListIndex)) & "'")) & " and " & Trim(IIf(Combo8.Text = "", "'=ALL'", "学生干部='" & Trim(Combo8.List(Combo8.ListIndex)) & "'")) & "" 'and 前后必须要有空格,否则就出错这是以前写的,你自己找些有用的吧
      

  3.   

    ADODB.RecordSet.Find 只支持单个字段的查找,多个字段应该用 Filter
      

  4.   

    用Filter的不好,用了之后,不能用上下翻页功能,如何解决这问题呢?
      

  5.   

    Find和Filter都不好,数据量大了的话,你就知错了.
      

  6.   

    Find 只能支持一个字段。可以这样:
    1 表中设置一个 ID 字段(唯一值,例如自动增加)。
    2 另外用一个记录集查找你的目标记录的 ID,然后 Find 这个 ID。
    dim rs as new adodb.recordset
    Set rs = adodc1.RecordSet.ActiveConnection.Execute("Select ID From tablename Where 字段1='"& aa &"' and 字段2='"& aa &"'")
    adodc1.recordset.find "ID = "& rs!ID 
    rs.Close
    Set rs = Nothing