2011-05-15 79 views
5

親愛的專家, 我試圖在連接到adoquery DBGrid的篩選結果,取決於4個複選框用戶選擇,用戶可以選擇一個或更多的Fileds相應地過濾數據 我有這個代碼,我不知道如何通過「和/或不通過」它,如果用戶選擇兩個或多個複選框。Delphi-將參數傳遞給ADOquery

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你的幫助

回答

5

你可以重寫你的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; 
+1

謝謝你這麼多,你是一個拯救生命的人 – Amanda 2011-05-15 07:06:38