none
DataSet.RejectChanges : DataSet.HasErrors remains true RRS feed

  • Question

  • Hello,

    if i undo changes in my dataset by using .RejectChanges() the changes are correctly reseted to original value, but the .HasError Property is still true. i tried it on DataSet, DataTable and even DataRow - all the same. Its the same with AcceptChanges! The only thing worked is DataRow.ClearErrors - but i shouldnt need to call this manually!? (i would have to refacture all my project)

    greetz

    Lornster

    • Moved by CoolDadTx Wednesday, June 4, 2014 6:14 PM ADO.NET related
    Wednesday, June 4, 2014 10:31 AM

Answers

  • That is by design.  DataSet.HasErrors simply enumerates the tables and calls HasErrors on each one. DataTable.HasErrors enumerates the rows and checks the HasErrors property as well.

    The implementation of DataRow.HasErrors simply looks to see if any error has occurred. This is a cached value so calling ClearErrors resets it.  The error property can be set programmatically but in general it is set by one of the constraints that are applied to the associated column.  RejectChanges temporarily turns of constraint checking while the rollback runs so error state will not be updated.  Since RejectChanges rolls back data to the last valid state there should never be any errors (otherwise how was the data saved originally).  If you need the error state to be refreshed you could enumerate through the tables/rows and call ClearError on each one.  I would recommend that you add an extension method on DataSet and DataTable to make it easier.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Wednesday, June 4, 2014 6:14 PM

All replies

  • That is by design.  DataSet.HasErrors simply enumerates the tables and calls HasErrors on each one. DataTable.HasErrors enumerates the rows and checks the HasErrors property as well.

    The implementation of DataRow.HasErrors simply looks to see if any error has occurred. This is a cached value so calling ClearErrors resets it.  The error property can be set programmatically but in general it is set by one of the constraints that are applied to the associated column.  RejectChanges temporarily turns of constraint checking while the rollback runs so error state will not be updated.  Since RejectChanges rolls back data to the last valid state there should never be any errors (otherwise how was the data saved originally).  If you need the error state to be refreshed you could enumerate through the tables/rows and call ClearError on each one.  I would recommend that you add an extension method on DataSet and DataTable to make it easier.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Wednesday, June 4, 2014 6:14 PM
  • ok thanks.

    my problem to understand is why RejectChanges doesnt reset the cached error value. but ok looks like i have to accept it and do it myself

    Wednesday, June 18, 2014 9:02 AM