本帖最后由 snowflying928 于 2009-08-06 16:53:31 编辑

解决方案 »

  1.   

    applyUpdates,CommitUpdates适用于批量提交的
    CommitUpdates在applyUpdates成功后,清除缓存,具体看看帮助,写的很清楚
      

  2.   


    这两个是数据集的方法Commit是数据库连接的方法,和StartTransaction,Rollback一起使用,就是事务提交更新,保证此事务更新的一致性和完整性(此事务内只要有一个更新异常,将导致此事务所有更新无效,就是回滚rollback),和  ADOConnection.BeginTrans;
    try
      //update
      
      ADOConnection.CommitTrans;
    except
      ADOConnection.RollbackTrans
    end类似post就是普通的将数据集修改提交到数据库
      

  3.   

    The following procedure illustrates how to apply a dataset’s cached updates to a database in response to a button click: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;这个是帮助里面的
      

  4.   

    我比较困惑的地方是在:
    资料什么时候在本地客户端的缓存中,何时会在DB端的缓存中,何时又会提交到数据库文件中。
    我之前的理解是:
    post只是把数据提交到本地的内存中。
    applyUpdates 是把数据提交到数据库的缓存中。
    Commit是提交到资料库中。如果在ApplyUpdates后并没有commit,资料是否会丢失呢?
    CommitUpdates 我很少使用到。今天学习了谢谢sparklerl在请教一下CommitUpdates 在什么样的时机下使用呢?如果我不用使用CommitUpdates 最程序会造成什么样的影响?
      

  5.   

    post;//直接提交数据给数据库
    applyUpdates//用于数据批量提交更新,单独用的时候,不用commit,如果结合食物的话,需要commit
    CommitUpdates//在applyUpdates之后,清空缓存
    Commit//是用在食物中的一种方法例子
       adoconnection.BeginTrans;//事物开始
        adoquery.post;//提交更改
        adodataset.applyupdates;//提交更新
       adoconnection.CommitTrans;//确认更新,在这一步之前,post,applyupdates提交的数据还没有保存到数据库,只有这一步执行了,才保存到数据库
       adodataset.CommitUpdates;//清空缓存~~