新增代碼: 
…………
…………
   begin
        with dm1.Query1 do
        begin
            append;
            fieldbyname('EMPLYID').AsString:=dbedit1.Text;
            fieldbyname('EMPLYNAME').AsString:=dbedit2.Text;
            fieldbyname('BUILDID').AsString:=dbedit3.Text;
            fieldbyname('ROOMID').AsString:=dbedit4.Text;
            fieldbyname('INS_DATE').AsDateTime:=Date; //或Date()
        end;
     end;
…………
…………保存代碼:
………………
………………
    with dm1 do
    begin
        try
          query1.ApplyUpdates;
          database1.Commit;
        except
           query1.CancelUpdates;
           database1.Rollback;
           i:=1;
        end;
        query1.CommitUpdates;
    end;
…………
…………爲什麽在點擊“保存”按鈕時,總是提示錯誤:
No user transaction is currently progress?
如何解決?謝謝!!

解决方案 »

  1.   

    如果你用了事务,那么要先开始事务。。给你个例子
    procedure TForm1.ApplyButtonClick(Sender: TObject);begin
      with CustomerQuery 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;end;