查询问题。

Rose1234567890 2003-08-23 09:08:31
有combobox1,combobox2,combobox3,combobox4这样四个控件。想做一个查询。
如果让它们任意组合都能查到数据库中的内容。如何设计这个查询呀?寻找最好的办
法。我用的办法太笨了。初学DELPHI对程序设计也不是太懂。没思路。请多多指教。
不要嫌我太笨呀。
...全文
56 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
dickeybird888 2003-08-23
  • 打赏
  • 举报
回复
query1.close;
query1.sql.clear;
query1.sql.add('select * from table where 1=1 ');
if combobox1.text<>'' then
query1.sql.add(' and name='''+combobox1.text+'''');
if combobox2.text<>'' then
query1.sql.add(' and unit='''+combobox2.text+'''');
if combobox3.text<>'' then
query1.sql.add(' and sex='''+combobox3.text+'''');
if combobox4.text<>'' then
query1.sql.add(' and address='''+combobox4.text+'''');
query1.open;
zhangxinji 2003-08-23
  • 打赏
  • 举报
回复
sql语句十一行上的,
字段名和like之间是有空格的
别忘了啊
zhangxinji 2003-08-23
  • 打赏
  • 举报
回复
这4个combobox连的字段如果为字符型字段
用下面的方法
query1.close;
query1.sql.clear;
query1.sql.add('select * from 表名 where 字段1 like '+''''+cobobox1.text+'%'+''''+'and 字段2 like '+''''+cobobox2.text+'%'+''''+'and 字段3 like '+''''+cobobox3.text+'%'+''''+'and 字段4
like '+''''+cobobox4.text+'%'+'''');
query1.execsql;
query1.open;
我经常用以上方法做多条件查询
可能效率要低一些,不过如果你的记录不会超过100万条是看不出来慢的
你试试啊
小弟也是初学者
有机会多交流啊

myboor 2003-08-23
  • 打赏
  • 举报
回复
不明白你的意思

2,495

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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