急求:模糊查询,关键字查询问题的解决办法

MoQi_123 2005-07-02 09:22:09
使用的是Access数据库.
有什么办法可以做到类似于Google搜索中的,输入一个或几个关键字,就可以查询到一个表中每个字段中符合条件的记录?

谢谢
...全文
263 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
conan1211 2005-07-02
  • 打赏
  • 举报
回复
select * from CarInfo where Color like '%红%' and Title like '%马力%' and Description like '%保修%'
如果Color字段对应的是红 ,Title对应的是马力,Description对应的是保修的话
如果对应关系不对,你也可以自己调整一下
MoQi_123 2005-07-02
  • 打赏
  • 举报
回复
谢谢大家的回复!

比如:
数据库中表CarInfo.字段有:ID,Title,Description,Color.
现在通过输入框输入:红 马力 保修
搜索结果应该包括"红色,马力规格,保修约定"等等内容.

这个通过什么方式实现呢?
lywf 2005-07-02
  • 打赏
  • 举报
回复
up
redstorm11 2005-07-02
  • 打赏
  • 举报
回复
up
jinbingg 2005-07-02
  • 打赏
  • 举报
回复
那是全文检索
renyu732 2005-07-02
  • 打赏
  • 举报
回复
CONTAINS:(关键字)
(说明) Predicate Finds words in the order specified, such as "Romeo and Juliet."

FREETEXT:(关键字)
(说明)Predicate Finds one or more words specified, such as "apples oranges pears."
FORMSOF::(关键字)
说明:Predicate Finds word variations, such as "gardening" and "garden."
LIKE:(关键字)
说明:Predicate Finds characters that match a specified string. The percent character (%) matches any or no characters adjacent to the specified string. For example, "%he ca%" matches "the cat."
yegucheng 2005-07-02
  • 打赏
  • 举报
回复
把关键字,以空格分成一个一个字符串,
更好的利用索引,查询速度更快,建议用:
select * from tablename where (字段 like '%条件1' or 字段 like '条件1%' or 字段 like '%条件2' or 字段 like '条件2%') and 其他条件
colinliu 2005-07-02
  • 打赏
  • 举报
回复
select * from tablename where 字段 like '%dd%'
微量科技 2005-07-02
  • 打赏
  • 举报
回复
select * from table where 字段 like '%关键字%'
新鲜鱼排 2005-07-02
  • 打赏
  • 举报
回复
up
conan1211 2005-07-02
  • 打赏
  • 举报
回复
select * from 表名 where 字段名 like %关键字%
注意
关键字的左边加%就是关键字的哪边模糊查询
shixianyong 2005-07-02
  • 打赏
  • 举报
回复
select * from iqcreport where iqc_bh like '%" + TextBox1.Text + "%'"
chenlixin007 2005-07-02
  • 打赏
  • 举报
回复
string KeyWord="红 马力 保修";
//拆分关键字
string[] SqlWhere=KeyWord.Split(' ');
//去空格
for(int i=0;i<SqlWhere.Length;i++)SqlWhere[i]=SqlWhere[i].Replace(" ","");
//构造where子句
//看你的具体情况了

//首先是全包括的
String Sql="where";
for(int i=0;i<SqlWhere.Length-1;i++)
{
Sql=Sql+" Color like '%"+SqlWhere[i]+"%' ";//多字段自己去加
Sql=Sql+" and "
}
Sql=Sql+" Color like '%"+SqlWhere[i]+"%' ";
//作查询返回


//其次是部分包括的
String Sql="where";
for(int i=0;i<SqlWhere.Length-1;i++)
{
Sql=Sql+" Color like '%"+SqlWhere[i]+"%' ";//多字段自己去加
Sql=Sql+" or "
}
Sql=Sql+" Color like '%"+SqlWhere[i]+"%' ";
//作查询返回
conan1211 2005-07-02
  • 打赏
  • 举报
回复
你可以把它们拼起来
看起来方便一些

string sSql = "select * from CarInfo where Color like '%红%' ";
sSql += "and Title like '%马力%' and Description like '%保修%'";
MoQi_123 2005-07-02
  • 打赏
  • 举报
回复
谢谢
先试一把

不过有20个字段,这样不是要写很长的SQL语句了?

110,552

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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