以前用D5的时候是这样写的:
  Query1.Post;
  Database.StartTransaction;
  Database.ApplyUpdates;
  Database.CommitUpdates;而到了D7下,这样写却出错:
 Query1.Post;
 Database.StartTransaction;
 Database.ApplyUpdates([]);
 Datebase.Commit;出错信息为: A user Transaction is Already in Progress.
我试过去掉这一句:Database.ApplyUpdates([]);
不会出错,但是提交不了。谁帮忙解决一下?谢谢!!

解决方案 »

  1.   

    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
      

  2.   

    看看Delphi7的帮助文件吧:它会自动开始一个事务Applying updates is a two-phase process that takes place within the context of the database component’s transaction control. When an application calls ApplyUpdates, the following events take place:1 A database transaction starts.(**********************)
    2 Cached updates are written to the database (Phase 1).If the database write is successful:1  Database changes are committed, ending the transaction.
    2  Cached updates are committed, clearing the internal cache buffer (Phase 2).If the database write fails database changes are rolled back, ending the transaction.The two-phased approach allows for effective error recovery, especially when updating multiple and interrelated datasets (for example, the datasets associated with a master/detail form).
      

  3.   

    在下已经自己解决了.应该这样写: 
    Query1.Post;
    Database.ApplyUpdates([Query1]);
    Database.StartTransaction;
    Datebase.Commit;
      

  4.   

    Query1.Post;
      DM.dbCrm.ApplyUpdates([Query1]);
      DM.dbCrm.StartTransaction;
      DM.dbCrm.Commit;