请帮忙看下面的代码:从表1中取出数据插入到表2中:
错误提示:操作符丢失: 
  with ADOQuery1 begin
       close;
       with SQL do begin
       clear;
       add('select * from table1');
       end;
       open;       while not ADOQuery1.eof do
          begin
            rtmp.id:=ADOQuery1.fieldbyname('id').AsInteger;
            rtmp.iname:=ADOQuery1.fieldbyname('MachineNo').AsString;
           
            //insert to table2   
            ADOQuery2.close;
            ADOQuery2.SQL.Clear;
            ADOQuery2.SQL.add('insert.....');
            ADOQuery2.Prepared;
            ADOQuery2.ExecSQL              ADOQuery1.Next;
          end;
    end;

解决方案 »

  1.   

    好的!!
     function SelAndIns():longint
     var rtmp:record1
     begin 
       
        with ADOQuery1 begin
           close;
           with SQL do begin
           clear;
           add('select * from table1');
           end;
           open;       while not ADOQuery1.eof do
              begin
                rtmp.id:=ADOQuery1.fieldbyname('id').AsInteger;
                rtmp.name:=ADOQuery1.fieldbyname('MachineNo').AsString;
               
                //insert to table2   
                ADOQuery2.close;
                ADOQuery2.SQL.Clear;
                ADOQuery2.SQL.add('insert into table2(ID,Name)');
                ADOQuery2.SQL.add('values('+inttostr(rtmp.id));
                ADOQuery2.SQL.add(','''+rtmp.name+'''); 
                ADOQuery2.Prepared;
                ADOQuery2.ExecSQL              ADOQuery1.Next;
              end;
        end;
        Result:=1
    end;
      

  2.   

    改为:
    ADOQuery2.SQL.add('insert into table2(ID,Name)');
                ADOQuery2.SQL.add('values('+inttostr(rtmp.id));
                ADOQuery2.SQL.add(','''+rtmp.name+'''+')'); 
                ADOQuery2.Prepare;
      

  3.   

    ok!!
    改为:
    ADOQuery2.SQL.add('insert into table2(ID,Name)');
                ADOQuery2.SQL.add('values('+inttostr(rtmp.id));
                ADOQuery2.SQL.add(','''+rtmp.name+''')'); 
                ADOQuery2.Prepare;
     pilicat(delphi迷) ( 20分)
      

  4.   

    是的,ID如果为自动增减字段,用insert语句时应当它不存在。