像C中的EXEC SQL SELECT * FROM ....的用法而不必拘泥于控件中使用。
请大虾指点。万分感谢。

解决方案 »

  1.   

    with ADOQuery1 do
    begin
    if active then
      close ;
    sql.clear ;
    sql.add('select * from ...');
    sql.prepare := true ;
    sql.open ;
      

  2.   

    with ADOQuery1 do
    begin
    close ;
    sql.clear ;
    sql.add('select * from ...');
    prepared;
    open ;
    end;
    这是控件用法,其他的方法好像不太行吧,学习中
      

  3.   

    用个函数:)Function ExecSqlS(s : String ) : Boolean ;
    begin
      with TADOQuery.Create(nil) do
      begin
        try
          Connection := ... ; // ConnectionString := ... ;
          Sql.Text := s ;
          ExecSql ;
        Except
        end ;     
        if Active then Active := False ;
        Free ;
      end ;
    end ;每次执行时 ,   ExecSqlS('...') ;
      

  4.   

    用个函数:)Function ExecSqlS(s : String ) : Boolean ;
    begin
      Result := True ;
      with TADOQuery.Create(nil) do
      begin
        try
          Connection := ... ; // ConnectionString := ... ;
          Sql.Text := s ;
          ExecSql ;
        Except
          Result := False ;
        end ;     
        if Active then Active := False ;
        Free ;
      end ;
    end ;每次执行时 ,   ExecSqlS('...') ;
      

  5.   

    procedure TForm1.Button2Click(Sender: TObject);
    const
    ss='select ybtdgl0,YBTZPRQ,cwdzdmc from hpcx,cwdzd where ybtyszl=''1'' and hpcx.ybtfcwd=cwdzd.cwdzddm and hpcx.ybtzprq=''%s''';
    begin
    with adoqcx do
    begin
    close;
    sql.Clear;
    sql.add(format(ss,[formatdatetime('yyyymmdd',Now())]));
    open;
      adoqcx.First;
        while not adoqcx.Eof do
          begin
          adothpcx1.open;
          adothpcx1.append;
          adothpcx1.FieldByName('rq').asstring:=adoqcx.FieldByName('YBTZPRQ').AsString;
          adothpcx1.FieldByName('cwd').asstring:=adoqcx.FieldByName('cwdzdmc').AsString;
          adothpcx1.FieldByName('fjzzl').AsInteger:=adoqcx.FieldByName('ybtdgl0').asinteger;
          adoqcx.Next;
          end;
          adothpcx1.post;
          showmessage('提取完成');end;
    end;