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