none
Cancel changes for database-less dataset? RRS feed

  • Question

  • I'm developing an application that maintains a strongly-typed dataset but serializes the dataset as XML - it does not have any underlying database.

    I'd like to be able to roll back all changes to the dataset (with changes distributed among multiple tables) to a particular point (in order to support a Cancel button on a form through which the dataset is manipulated. I was under the impression that this could be done by wrapping all changes within a TransactionScope, but after trying this I've determined that the TransactionScope has no effect - all changes get persisted regardless.

    Is there a way to do this other than by operating on a copy of the dataset and then manually overwriting the original to commit changes?
    Monday, October 12, 2009 9:19 PM

Answers

All replies

  • The DataSet.RejectChanges() should work. It will roll everything back to whenever you last did an .AcceptChanges().
    ~~Bonnie Berent [C# MVP]

    (new blog --- not many posts yet --- be patient)
    geek-goddess-bonnie.blogspot.com
    • Marked as answer by Yichun_Feng Monday, October 19, 2009 1:35 AM
    Monday, October 12, 2009 9:22 PM
  • It may work, but it's not perfect. As I understand it, AcceptChanges() is equivalent to recursively calling AcceptChanges() on all subordinate objects in the dataset. I have subdialogs on the form that allow modification of datarows that also have OK/Cancel buttons. It seems to me that if I the OK buttons on those dialogs corresponds to AcceptChanges on the datarows then those changes get committed so that RejectChanges on the dataset will not actually roll back any of those changes. Basically, I want to be able to nest commit/rollback fuctionality a few levels deep.

    Of course, I'll understand if this isn't implemented natively but want to make sure that it isn't before rolling something on my own.

    Tuesday, October 13, 2009 6:22 PM
  • You're correct that a DataSet AcceptChanges/RejectChanges would be applied for the entire DataSet, just like a DataTable Accept/Reject would apply only to one particular DataTable and a DataRow Accept/Reject would apply only to one particular DataRow.

    But apparently, this does NOT sound like what you want to do with your dialogs.. I think you're going to have to roll your own on this one. If there is already a way to do this, I don't know about it ...  that doesn't mean there isn't a native way to do it ... it just means I don't know everything. ;0)
    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Wednesday, October 14, 2009 2:52 PM