【问题标题】:Delphi- Passing parameters to ADOqueryDelphi - 将参数传递给 ADOquery
【发布时间】:2011-05-15 06:48:18
【问题描述】:

尊敬的专家, 我正在尝试过滤连接到 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;

等待你的帮助

【问题讨论】:

    标签: delphi ado parameter-passing


    【解决方案1】:

    你可以将你的 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-11
      • 1970-01-01
      • 1970-01-01
      • 2010-11-12
      • 1970-01-01
      • 2019-09-27
      • 1970-01-01
      相关资源
      最近更新 更多