QRYTEMP2.SQL.Add('DELETE FROM QM_WIP2_MRB_Y_DETAIL;'); 
QRYTEMP2.SQL.Add('INSERT INTO QM_WIP2_MRB_Y_DETAIL( USER_3,SCRAP_UM)('+SQLTXT1+');');
QRYTEMP2.SQL.Add('INSERT INTO QM_WIP2_MRB_Y_DETAIL(USER_4,SCRAP_UM)('+STR1+');');
QRYTEMP2.SQL.Add('DELETE FROM QM_TEMP_WIP2ST_RECORD;');
QRYTEMP2.ExecSQL;
 with  qrytemp2 do
  begin
  Database1.StartTransaction;
    try
      ApplyUpdates; {try to write the updates to the database};
      Database1.Commit; {on success, commit the changes};
    except
      Database1.Rollback; {on failure, undo the changes};
    raise; {raise the exception to prevent a call to CommitUpdates!}
    end;
  CommitUpdates; {on success, clear the cache}
  end;有錯誤,該怎麽寫啊?

解决方案 »

  1.   

    一个个分开来啊
    QRYTEMP2.SQL.Add('DELETE FROM QM_WIP2_MRB_Y_DETAIL;'); 
    QRYTEMP2.ExecSQL;
    QRYTEMP2.SQL.Add('INSERT INTO QM_WIP2_MRB_Y_DETAIL( USER_3,SCRAP_UM)('+SQLTXT1+');');
    QRYTEMP2.ExecSQL;
    .
    .
    .
      

  2.   

    我想讓 delete insert  ....同時提交,如果分開執行,第二個sql提交後 ,如果另一個用戶
    這時候執行了第一個sql,表裏面的數據就被刪掉了
    要是芳到過程裏面,查詢條件太多了我不知道query可不可以這麽寫?
      

  3.   

    你这样写就是把所有的SQL语句连接在一起了,如果非要添加和删除同时执行,那你只能用存储过程了
      

  4.   

    procedure TForm1.panduanzhuce1;
    begin
       dm.adoconnection1.BeginTrans;
       try
        dm.ADOQuery4.Close;
        dm.ADOQuery4.sql.clear;
        dm.ADOQuery4.SQL.add('select  password   from users where mobile_phone='''+s+'''');
        dm.ADOQuery4.Open;
        if  dm.ADOQuery4.RecordCount <= 0 then
          begin
            dm.ADOQuery2.Close;
            dm.ADOQuery2.sql.clear;
            dm.ADOQuery2.SQL.add('insert into t_smssent(f_mobile,f_msgcontent,f_status) values('''+s+''',''请您先注册!'',0)');
            dm.ADOQuery2.ExecSQL;
          end;
          dm.ADOQuery3.Close;
          dm.ADOQuery3.sql.clear;
          dm.ADOQuery3.SQL.add('update t_smsreceived set f_status=1 where f_id='+sss+'');
          dm.ADOQuery3.ExecSQL;
          dm.adoconnection1.CommitTrans;
      except
        dm.adoconnection1.RollbackTrans;
      end;
    end;