一个简单的查询问

pengpeng2004 2004-10-21 09:40:47
各位大虾好!
我用ADODC控件查询,怎么报错呢?写法如下
adodc1.recordset.find "字段1='"& aa &"' and 字段2='"& aa &"'"
这样写有错吗?
如adodc1.recordset.find "字段1='"& aa &"'" 写可以查询,为什么联两个字段以上用find不能查呢?我错在哪??
...全文
175 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengpeng2004 2004-10-22
  • 打赏
  • 举报
回复
哪如何解决我上面的问题呢?
warlord 2004-10-22
  • 打赏
  • 举报
回复
同意楼上
of123 2004-10-22
  • 打赏
  • 举报
回复
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
soupeven 2004-10-22
  • 打赏
  • 举报
回复
关注!顶啊!
海洋微风 2004-10-21
  • 打赏
  • 举报
回复
Find和Filter都不好,数据量大了的话,你就知错了.
pengpeng2004 2004-10-21
  • 打赏
  • 举报
回复
用Filter的不好,用了之后,不能用上下翻页功能,如何解决这问题呢?
Tiger_Zhao 2004-10-21
  • 打赏
  • 举报
回复
ADODB.RecordSet.Find 只支持单个字段的查找,多个字段应该用 Filter
pengpeng2004 2004-10-21
  • 打赏
  • 举报
回复
我不要用SQL写的啊
starsoulxp 2004-10-21
  • 打赏
  • 举报
回复
up
tj123 2004-10-21
  • 打赏
  • 举报
回复
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 前后必须要有空格,否则就出错

这是以前写的,你自己找些有用的吧
tj123 2004-10-21
  • 打赏
  • 举报
回复
错就错在你要分开写查询的字段,and两边的字段要用引号分开的

像这样写
strsearch = Trim(Text1.Text)
strtable = "目录"
strFilter = " " & stroption & " like " & " '%" & strsearch & "%' "
strgoods = "*" '"内容"

strSQL = "select " & strgoods & " from " & strtable & " where " & stroption & " like '%" & strsearch & "%'"

7,765

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧