strSql:='select * from tablename wehre 1=1' if trim(Edit1.text)<>'' then strSql:=strSql+' and column1='''+ trim(Edit1.text) +'''' if trim(Edit2.text)<>'' then strSql:=strSql+' and column2='''+ trim(Edit2.text) +'''' 。
在每个条件控件前面加上一个CHECKBOX就可以了. CHECKED = SQLSTR = ' AND 条件 ' UNCHECKED = SQLSTR := ' And 1 = 1 '//1=1是很有用的小TRICK 然后把SQLSTR相加组成最终的查询条件就可以了.
判斷查詢條件的輸入框是否有了改變 如果不是初始的狀態 就添加到查詢語句 ... Sql.add(..where 1=1)//加上1=1是為了拚語句,這樣防止一個不選就出錯 if edit1.text<>'' then begin Sql.add('and id =:id); Paramerters.ParamByName('id').Value:=edit1.text; end; if Combobox1.itemindex>0 then begin Sql.add('and whcd =:whcd); Paramerters.ParamByName('whcd').Value:=Combobox1.text; end;
编号:从( )到( )
文化程度:下拉列表框(有4个选项)
出生日期:Timepicker(可选时间),从() 到()
工龄:下拉列表框(有4个选项)然后可以根据其中一个查询,也可以任意组合查询
怎样实现?
if trim(Edit1.text)<>'' then
strSql:=strSql+' and column1='''+ trim(Edit1.text) +''''
if trim(Edit2.text)<>'' then
strSql:=strSql+' and column2='''+ trim(Edit2.text) +''''
。
CHECKED = SQLSTR = ' AND 条件 '
UNCHECKED = SQLSTR := ' And 1 = 1 '//1=1是很有用的小TRICK
然后把SQLSTR相加组成最终的查询条件就可以了.
...
Sql.add(..where 1=1)//加上1=1是為了拚語句,這樣防止一個不選就出錯
if edit1.text<>'' then
begin
Sql.add('and id =:id);
Paramerters.ParamByName('id').Value:=edit1.text;
end;
if Combobox1.itemindex>0 then
begin
Sql.add('and whcd =:whcd);
Paramerters.ParamByName('whcd').Value:=Combobox1.text;
end;