简体   繁体   English

Delphi-将参数传递给ADOquery

[英]Delphi- Passing parameters to ADOquery

Dear experts, I'm trying to filter the result in dbgrid connected to adoquery, depending on user selection of 4 checkboxes, user can select one or more fileds to filter the data accordingly I have this code, and I don't know how to pass "and/ or not pass" it if user select two or more checkboxes. 尊敬的专家,我正在尝试过滤连接到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;

waitting your help 等待你的帮助

you can rewrite your sql sentence to (check the final 1=1) 您可以将sql语句重写为(检查最后的1 = 1)

select * from Vw_Activity where 1=1

and then add each condition like this 然后像这样添加每个条件

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM