可以用SQL的模糊查询啊!很简单的!!举个例子吧! ADOQuery.active:=false; ADOQuery.SQL.Text:='select * from Deptment where dept like'+quotedstr('%'+iwcombobox2.Text+'%')+'and station like'+quotedstr('%'+iwcombobox3.Text+'%'); ADOQuery.Active:=true; 去试试吧!!
是不是where后面的条件个数不一定?s:='select * from table where 1=1'; if edit1.text<>'' then s:=s+' and field1='''+edit1.text+''''; if edit1.text<>'' then s:=s+' and field2='''+edit2.text+''''; ...
可以是动态参数传给ADO里的SQL来执行查询吧!
是不是多条件组合查询啊?如果是,用SQL语句查询,DBGrid也会显示符合条件的结果啊! SQL='Select * from 数据表名 where'if CheckBox1.Checked =true then begin dd(0)=true sql=sql + 'CheckBox1所指的字段 ='+ '输入条件值' end if CheckBox2.Checked =true then begin dd(1)=true if dd(0) then //CheckBox1已选中 sql=sql + 'and CheckBox2所指的字段 ='+ '输入条件值' else //CheckBox1未选中 sql=sql + 'CheckBox2所指的字段 ='+ '输入条件值' end if not dd(0) or dd(1) then messagebox('请选择查询方式')
那和adoquery也没有关系呀。。 var sqlstr:string; sqlstr:='select * from a where 1=1'; if edit1.text<>'' then sqlstr=sqlstr+' and 字段='''+edit1.text+''''; if ....2................. adoquery1.close; adoquery1.sql.text:=sqlstr; adoqueyr1.open;
ADOQuery.active:=false;
ADOQuery.SQL.Text:='select * from Deptment where dept like'+quotedstr('%'+iwcombobox2.Text+'%')+'and station like'+quotedstr('%'+iwcombobox3.Text+'%');
ADOQuery.Active:=true;
去试试吧!!
if edit1.text<>'' then s:=s+' and field1='''+edit1.text+'''';
if edit1.text<>'' then s:=s+' and field2='''+edit2.text+'''';
...
是不是多条件组合查询啊?如果是,用SQL语句查询,DBGrid也会显示符合条件的结果啊!
SQL='Select * from 数据表名 where'if CheckBox1.Checked =true then
begin
dd(0)=true
sql=sql + 'CheckBox1所指的字段 ='+ '输入条件值'
end
if CheckBox2.Checked =true then
begin
dd(1)=true
if dd(0) then //CheckBox1已选中
sql=sql + 'and CheckBox2所指的字段 ='+ '输入条件值'
else //CheckBox1未选中
sql=sql + 'CheckBox2所指的字段 ='+ '输入条件值'
end
if not dd(0) or dd(1) then
messagebox('请选择查询方式')
如果你想做的好的话,写一个动态组建,我是这样做的
var
sqlstr:string;
sqlstr:='select * from a where 1=1';
if edit1.text<>'' then sqlstr=sqlstr+' and 字段='''+edit1.text+'''';
if ....2.................
adoquery1.close;
adoquery1.sql.text:=sqlstr;
adoqueyr1.open;