Z
zhhc
Unregistered / Unconfirmed
GUEST, unregistred user!
不好意思,是我加掉了一个空格,在网页上没看出来
procedure TForm1.BitBtn1Click(Sender: TObject);//这是查询代码
VAR
i,j,k:INTEGER;
s:tstringlist;
sql,t:string;
begin
s:=tstringlist.Create ;
for i:=0 to list1.Items.Count -1 do
if list1.Checked then
s.Add(list1.Items);
if s.Count =0 then
begin
s.Free;
exit;
end;
DBGrid1.DataSource:=DataSource1;
DataSource1.DataSet:=Query2;
sql:=s[0];
for i:=1 to s.Count -1 do
sql:=sql+','+s;
sql:='select'+SQL+' from JOBS';
t:=s[0];
s.clear;
for i:=0 to list2.Items.Count -1 do
if list2.Checked then
s.Add(list2.Items);
if s.Count>0 then
begin
sql:=sql+' where cast('+t+' as CHAR(30)) in ('''+s[0]+'''';
// ^这里有一个空格
for i:=1 to s.Count -1 do
sql:=sql+','''+s+'''';
sql:=sql+')';
end;
query2.SQL.Text :=sql;
query2.Active :=true;
s.Free;
end;
end.
procedure TForm1.BitBtn1Click(Sender: TObject);//这是查询代码
VAR
i,j,k:INTEGER;
s:tstringlist;
sql,t:string;
begin
s:=tstringlist.Create ;
for i:=0 to list1.Items.Count -1 do
if list1.Checked then
s.Add(list1.Items);
if s.Count =0 then
begin
s.Free;
exit;
end;
DBGrid1.DataSource:=DataSource1;
DataSource1.DataSet:=Query2;
sql:=s[0];
for i:=1 to s.Count -1 do
sql:=sql+','+s;
sql:='select'+SQL+' from JOBS';
t:=s[0];
s.clear;
for i:=0 to list2.Items.Count -1 do
if list2.Checked then
s.Add(list2.Items);
if s.Count>0 then
begin
sql:=sql+' where cast('+t+' as CHAR(30)) in ('''+s[0]+'''';
// ^这里有一个空格
for i:=1 to s.Count -1 do
sql:=sql+','''+s+'''';
sql:=sql+')';
end;
query2.SQL.Text :=sql;
query2.Active :=true;
s.Free;
end;
end.