2011-05-15 2 views
5

안녕하세요, 전문가 사용자가 4 개의 확인란을 선택하면 사용자가 dbqurid에 연결된 결과를 필터링하려고합니다. 사용자가 하나 이상의 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; 

당신의 도움을 기다리는 것 같은데

답변

5

당신은

select * from Vw_Activity where 1=1 

(최종 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

감사처럼 각 조건을 추가로 SQL 문장을 다시 작성할 수 있습니다 너는 너무, 너는 생명의 은인이야. – Amanda