for i:=0 to 8 do
begin
Query2.Active:=false;
Query2.SQL.Clear;
Query2.SQL.Text:='select A,B,C FROM DDD WHERE A=字符串(变化的数组,有具体的值)';
Query2.Active:=true;
end;
我想把循环的查询结果在DBGrid中显示出来,可以吗?

解决方案 »

  1.   

    为什么要连续打开数据集呢?
    要想显示到DBGRID中,只需数据源绑定就可以了!
      

  2.   

    Query2.Active:=false;
    Query2.SQL.Clear;
    for i:=0 to 8 do
    begin
    Query2.SQL.Text:='select A,B,C FROM DDD WHERE A=字符串(变化的数组,有具体的值)';
    end;
    Query2.Active:=true;
      

  3.   

    Query2.Active:=false;
    Query2.SQL.Clear;
    Query2.SQL.Text:='select A,B,C FROM DDD WHERE (a='+''''+字符串[0]+''''+')';
    for i:=1 to 8 do
    begin
    Query2.SQL.add('OR (A='+''''+字符串[i]+''''+')');
    end;
    Query2.Active:=true;-_-!
      

  4.   

    你的方法不行
    这样var
      S: string;
      I: Integer;
    begin
      for I := 0 to 8 do S := ',' + QuotedStr(数组[I]);
      if Length(S) = 0 then Exit;  Query2.Close;
      Query2.SQL.Text := 'select A,B,C FROM DDD WHERE A IN (' + S + ')';
      Query2.Open;
    end;
      

  5.   

    漏了一句var
      S: string;
      I: Integer;
    begin
      for I := 0 to 8 do S := ',' + QuotedStr(数组[I]);
      if Length(S) = 0 then Exit;  Delete(S, 1, 1);
      Query2.Close;
      Query2.SQL.Text := 'select A,B,C FROM DDD WHERE A IN (' + S + ')';
      Query2.Open;
    end;