在DBGrid中输入要添加的内容,或直接在TDGrid中修改内容,当指向其他记录是会自动提交,我想修改或添加完成时按保存按钮时再全部提交应该怎么办?我用的是ADOQuery,和Sybase数据库,请讲详细点。

解决方案 »

  1.   

    ADOQuery的lockType设置为ltBatchOptimistic
    提交时要用
    ADOQuery.UpdateBactch才行
    取消用ADOQuery1.CancelBatch
      

  2.   


    with ADODataSet1 do begin
      CursorLocation := clUseClient;
      CursorType := ctStatic;
      LockType := ltBatchOptimistic;
      CommandType := cmdText;
      CommandText := 'SELECT * FROM Employee';
      Open;
    end;
      

  3.   

    AppayUpdate太长时间不用了,有点记不清了
      

  4.   

    使用缓存提交步骤如下:
    1.比如你连接的表是用QUERY即query1
    2.你增加一个UpdateSQL即updatesql1
    3.将query1的updateobject设置为updatesql1
    4.设置query1的cachedupdate为真
    5.打开query1
    6.双击updatesql1,设置其key fields为表的主键值
    7.选择updatesql1的generate sql,单击即可
    8.这样就可以了
    9.在真正保存的代码中写:
    procedure TForm1.ApplyButtonClick(Sender: TObject);begin
      with Query1 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;
    就可以了