edt1,edt2,edt3,edt4分别用于输入查询字段a,b,c,d,如果edt1,edt2,edt3,edt4全部输入值那么a,b,c,d查询出既满足edt1又满足edt2又满足edt3又满足edt4,如果只输入一个或2个值,那么查询它所相对应的字段满足所输入的条件
解决方案 »
- 请教各位大虾,小弟想从数据库表中取得数据,并生成树形列表,应该怎么实现?
- 郁闷中.....
- 窗口停靠问题
- 如何判断一个数据库中是否存在某表?
- 大侠救急啊!我的delphi的tlabel控件的caption属性栏里没法显示中文,但是界面上可以显示中文,这是怎么回事啊,我都重装过几次了!!
- csdn的老大们,救我呀。真的分用完了。
- 关于delphi7 调用webservice的问题
- 请问setwindowshookex怎么用,谢谢!
- XE 执行了一个MessageDlg为什么会报错
- 《DELPHI5开发人员指南》中讲的数据类型
- delphi有类似C++中map容器吗?
- 我想更好更快地学习delphi7,请兄弟们支招。
var
SQLStr : String;
begin
if edt1.Text <> '' then
SQLStr := SQLStr + a条件
if edt2.Text <> '' then
SQLStr := SQLStr + b条件
if edt3.Text <> '' then
SQLStr := SQLStr + c条件
if edt4.Text <> '' then
SQLStr := SQLStr + d条件
end
sqlstr: string;
begin
sqlstr := format(' select * from tablename where f1 = isnull(''%s'',f1) '+
and f2 = isnull(''%s'',f2)
and f3 = isnull(''%s'',f3)
and f4 = isnull(''%s'',f4) ',[edit1.text,edit2.text,edit3.text,edit4.text]);
end;
var
strCond : String;//查询条件////再次假定a、b、c、d都是字符型
strCond :='';
if edt1.Text <> '' then
strCond := 'where a='''+edt1.text+''' ';
if edt2.Text <> '' then
begin
if strCond='' then
strCond := 'where b='''+edt2.text+''' '
else
strCond:=strCond+' and b='''+edt2.text+''' '
end;
if edt3.Text <> '' then
begin
if strCond='' then
strCond := 'where c='''+edt3.text+''' '
else
strCond:=strCond+' and c='''+edt3.text+''' '
end;
if edt4.Text <> '' then
begin
if strCond='' then
strCond := 'where d='''+edt4.text+''' '
else
strCond:=strCond+' and d='''+edt4.text+''' '
end;//应用查询条件
sql.add('select ...... from tableName '+strCond)
procedure TForm1.Button1Click(Sender: TObject);
Const
values:array[1..4] of string =(' AND 工号=',' AND 姓名=',' AND 部门=',' AND 职位=');
var
i:integer;
str:string;
begin str:='select * from x_eng where 1=1'; for i := 1 to 4 do
if trim(TEdit(FindComponent('Edit'+inttostr(i))).Text)<>'' then begin
str:=str+values[i]+QuotedStr(TEdit(FindComponent('Edit'+inttostr(i))).Text);
end;
with Adoquery1 do begin
close;
sql.text:=str;
open;
end;
end;