我在用ADO連接數據庫時,用adocommand 邊接數據庫﹐adocommand1.commandtext為一查詢語句﹐然后執行adodataset.recordset:=adocommand1.execute語句﹐得到一查詢結果﹐怎樣才能使得到的數據集保存為另一個數據表中﹐最好是一個新表中。
請高手指點﹐馬上給分。

解决方案 »

  1.   

    建立新表的话还是得要自己写sql语句。
      

  2.   

    参考
    procedure TAdoBatch.CreateTbable;
    var
    i,size:integer;
    field,fieldss,Ftype:string;
    begin
     FSourceTableList.Clear;
     for i:=0 to Fsourcequery.FieldCount-1 do
      begin
        size:=Fsourcequery.Fields[i].Size;
        case  Fsourcequery.Fields[i].DataType of
         ftInteger: Ftype:='INT';
         ftString: Ftype:='CHAR('+inttostr(size)+')';
         ftFloat:  Ftype:='FLOAT';
         ftDate,ftDateTime: Ftype:='DATETIME';
         ftCurrency: Ftype:='Currency';
         ftSmallint: Ftype:='smallint';
         ftBCD: Ftype:='NUMERIC(19,6)';
        else
         ftype:='CHAR('+inttostr(size)+')';
        end;  //case
        field:=Fsourcequery.Fields[i].FieldName+' '+Ftype;
        if uppercase(Fsourcequery.Fields[i].FieldName)<>'A0188' then
          FSourceTableList.Add(Fsourcequery.Fields[i].FieldName+' ['+Ftype+']');    if fieldss='' then fieldss:=field
          else fieldss:=fieldss+','+field;
      end;  //for
      //?aê??¨á¢IN_TEMP#±í
      with Fdestquery do
      begin
       Close;
       SQL.clear;
       SQL.Add('if exists(select*from sysobjects where name='+QuotedStr(FDestTablename)+')');
       SQL.Add('begin drop table '+FDestTablename +' end ');
       SQL.Add('create table '+FDestTablename+' ('+fieldss+')');
       ExecSQL;
      end; //with
    end;
      

  3.   

    select * into NewTb from OldTB
      

  4.   

    要保存就得一条一条的insert
    或直接用insert .... select .....