N
nancycm
Unregistered / Unconfirmed
GUEST, unregistred user!
想实现在checklistBox中选择一个或多个之后,把相应的数据显示出来,可为什么执行后
ADOQuery2.sql始终只是
select * from Orders where OrderID=xxx
而不是我想要的:
select * from Orders where OrderID=xxx or OrderID=xxx or OrderID=xxx ....
procedure TForm1.yesBtnClick(Sender: TObject);
var
sqlString:String;
I:Integer;
flag:boolean;
begin
flag:=false;
ADOQuery2.SQL.Clear;
sqlString:='select * from Orders where';
for I:=0 to CheckListBox1.Count-1 do
begin
if CheckListBox1.Selected then
begin
if flag then
sqlString:=sqlString+' or';
sqlString:=sqlString+' OrderID='+''''+CheckListBox1.Items+'''';
if not flag then
flag:=true;
end;
end;
ADOQuery2.SQL.Add(sqlString);
ADOQuery2.Active:=true;
ADOQuery2.ExecSQL;
end;
ADOQuery2.sql始终只是
select * from Orders where OrderID=xxx
而不是我想要的:
select * from Orders where OrderID=xxx or OrderID=xxx or OrderID=xxx ....
procedure TForm1.yesBtnClick(Sender: TObject);
var
sqlString:String;
I:Integer;
flag:boolean;
begin
flag:=false;
ADOQuery2.SQL.Clear;
sqlString:='select * from Orders where';
for I:=0 to CheckListBox1.Count-1 do
begin
if CheckListBox1.Selected then
begin
if flag then
sqlString:=sqlString+' or';
sqlString:=sqlString+' OrderID='+''''+CheckListBox1.Items+'''';
if not flag then
flag:=true;
end;
end;
ADOQuery2.SQL.Add(sqlString);
ADOQuery2.Active:=true;
ADOQuery2.ExecSQL;
end;