none
What is the relation between TableAdapterManager.BackupDatasetBeforeUpdate and DataSet.RejectChanges() ? RRS feed

  • Question

  • Hello,

    When an update fails while TableAdapterManager.UpdateAll(), I can catch the exception and call DataSet.RejectChanges() to roll back all the changes made to the dataset.
    So I wonder what is the purpose of TableAdapterManager.BackupDatasetBeforeUpdate, as it seems this is not necessary for DataSet.RejectChanges() to work.

    Thanks in advance.
    Tuesday, February 9, 2010 1:51 PM

Answers

  • Hi Emmanuel,

    Basically TableAdapterManager is providing update functionalities for related datasets instead of one, thus these two members are on different level. Although in your case, if you are working on a single dataset without relations, they should both work in some way.

    Reference in MSDN article Hierarchical Update Overview: http://msdn.microsoft.com/en-us/library/bb384567.aspx

    //************************************************//
    Creating a Backup Copy of a Dataset Before Performing a Hierarchical Update
    <!---->

    When you save data (by calling the TableAdapterManager.UpdateAll() method), the TableAdapterManager attempts to update the data for each table in a single transaction. If any part of the update for any table fails, the whole transaction is rolled back. In most situations, rolling back the transaction returns your application to its original state. However, sometimes you might want to restore the dataset from the backup copy. One example is when you are using auto-increment values. For example, if a save operation is not successful, auto-increment values are not reset in the dataset, and the dataset will continue to create auto-incrementing values, leaving a gap in numbering that might not be acceptable in your application. In situations where this is an issue, the TableAdapterManager provides a BackupDataSetBeforeUpdate property that replaces the existing dataset with a backup copy if the transaction fails.
    //************************************************//

    Hope this answers your question.

    Alex Qiu
    Visual Studio Team, Microsoft

    Friday, February 12, 2010 3:04 AM

All replies

  • Hi Emmanuel,

    Basically TableAdapterManager is providing update functionalities for related datasets instead of one, thus these two members are on different level. Although in your case, if you are working on a single dataset without relations, they should both work in some way.

    Reference in MSDN article Hierarchical Update Overview: http://msdn.microsoft.com/en-us/library/bb384567.aspx

    //************************************************//
    Creating a Backup Copy of a Dataset Before Performing a Hierarchical Update
    <!---->

    When you save data (by calling the TableAdapterManager.UpdateAll() method), the TableAdapterManager attempts to update the data for each table in a single transaction. If any part of the update for any table fails, the whole transaction is rolled back. In most situations, rolling back the transaction returns your application to its original state. However, sometimes you might want to restore the dataset from the backup copy. One example is when you are using auto-increment values. For example, if a save operation is not successful, auto-increment values are not reset in the dataset, and the dataset will continue to create auto-incrementing values, leaving a gap in numbering that might not be acceptable in your application. In situations where this is an issue, the TableAdapterManager provides a BackupDataSetBeforeUpdate property that replaces the existing dataset with a backup copy if the transaction fails.
    //************************************************//

    Hope this answers your question.

    Alex Qiu
    Visual Studio Team, Microsoft

    Friday, February 12, 2010 3:04 AM
  • Thank you very much for your response.
    It's very clear now that BackupDataSetBeforeUpdate is only usefull when leaving gaps in auto-increment fields is not an option.

    Tahnks again.

    Friday, February 12, 2010 10:27 AM