我用TDxDBGrid显示数据,并直接在Dxdbgrid里修改数据,我想在未提交数据之前,所有修改的数据是可以CANCEL的,但在dxdbgrid中修改一行数据后你选择另一条数据后,上述数据就自动提交到数据里了,我再次回滚事务已经不起作用,应该如何解决这种问题呢

解决方案 »

  1.   

    用ADOCONNECTION ADOConnection1.BeginTrans;//事务开始
       ADOConnection1.CommitTrans;//提交事务
       ADOConnection1.RollbackTrans//回滚
      

  2.   


     ADOConnection1.BeginTrans;//事务开始
    //中间你做的操作都是在这个事物以内的,中间你可以更新,插入,删除数据不过其中有一些操作是不可以逆转的,具体看看服务器说明文档;
    adoquery1.execsql;//和平时的没什么区别
     ADOConnection1.CommitTrans;//提交事务,在你提交之后你做的改变才永久保存
       ADOConnection1.RollbackTrans//回滚
    一般这样:
    ADOConnection1.BeginTrans;
    try
    //....一些操作
    ADOConnection1.CommitTrans;
    except
    ADOConnection1.RollbackTrans;
    end;