Delphi-将参数传递给ADOquery

亲爱的专家,
我正在尝试过滤连接到adoquery的dbgrid中的结果,具体取决于用户选择的4个复选框,用户可以选择一个或多个文件来相应地过滤数据
我有这个代码,如果用户选择两个或更多复选框,我不知道如何传递“和/或不传递”它.

Vw_Activity.SQL.Text:='select * from Vw_Activity where ';
if CBEmployee.Checked then
begin
Vw_Activity.SQL.Add('Emp_Name_Ar=:x');
Vw_Activity.Parameters.ParamByName('x').Value:=emp Name.Text;
end;


if CBTask.Checked then
begin
Vw_Activity.SQL.Add('Category_Name=:y');
Vw_Activity.Parameters.ParamByName('y').Value:=Pro blemCat.Text;
end;

if CBIncharge.Checked then
begin
Vw_Activity.SQL.Add('Support_name_En=:h');
Vw_Activity.Parameters.ParamByName('h').Value:=Sup portstaff.Text;
end;


if CBstatus.Checked then
begin
Vw_Activity.SQL.Add('Request_Status=:k');
Vw_Activity.Parameters.ParamByName('k').Value:=Req uestStatus.Text;
end;

Vw_Activity.Active:=true;

等你的帮助

解决方法

你可以重写你的sql句子(检查最后的1 = 1)

select * from Vw_Activity where 1=1

然后添加这样的每个条件

Vw_Activity.SQL.Text:='select * from Vw_Activity where 1=1 ';
if CBEmployee.Checked then
begin
  Vw_Activity.SQL.Add('AND Emp_Name_Ar=:x');
  Vw_Activity.Parameters.ParamByName('x').Value:=emp Name.Text;
end;


if CBTask.Checked then
begin
  Vw_Activity.SQL.Add('AND Category_Name=:y');
  Vw_Activity.Parameters.ParamByName('y').Value:=Pro blemCat.Text;
end;

if CBIncharge.Checked then
begin
  Vw_Activity.SQL.Add('AND Support_name_En=:h');
  Vw_Activity.Parameters.ParamByName('h').Value:=Sup portstaff.Text;
end;


if CBstatus.Checked then
begin
  Vw_Activity.SQL.Add('AND Request_Status=:k');
  Vw_Activity.Parameters.ParamByName('k').Value:=Req uestStatus.Text;
end;

Vw_Activity.Active:=true;

相关文章

 从网上看到《Delphi API HOOK完全说明》这篇文章,基本上都...
  从网上看到《Delphi API HOOK完全说明》这篇文章,基本上...
ffmpeg 是一套强大的开源的多媒体库 一般都是用 c/c+&#x...
32位CPU所含有的寄存器有:4个数据寄存器(EAX、EBX、ECX和ED...
1 mov dst, src dst是目的操作数,src是源操作数,指令实现的...