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;
这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万条是看不出来慢的
你试试啊
小弟也是初学者
有机会多交流啊