var S: String; i: Integer; begin S:= ''; for i := 0 to ListBox1.Items.Count - 1 do begin if S = '' then S := QuotedStr(ListBox1.Items[i]) else S := S + ',' + QuotedStr(ListBox1.Items[i]); end; if S = '' then S := ' where 1 <> 1 ' else S := ' where 字段名 in (' + S +')'; ADOQuery1.Close; ADOQuery1.SQL.Text := 'select * from 表名 ' + S; ADOQuery1.Open; end;
S: String;
i: Integer;
begin
S:= '';
for i := 0 to ListBox1.Items.Count - 1 do
begin
if S = '' then
S := QuotedStr(ListBox1.Items[i])
else
S := S + ',' + QuotedStr(ListBox1.Items[i]);
end; if S = '' then
S := ' where 1 <> 1 '
else
S := ' where 字段名 in (' + S +')';
ADOQuery1.Close;
ADOQuery1.SQL.Text := 'select * from 表名 ' + S;
ADOQuery1.Open;
end;
另说明一下:
ListBox的内容作为查询条件的话,其内容最好只针对一个字段,不然的话,嗯,我是实现不了。楼上的应该可以。