none
Rolling back transactions, RowState... RRS feed

  • Question

  • Hi everyone,

    If I have the following method

    private void Save( DataRow row1, DataRow row2 )
    {
      // Create transaction code here....

    // Create table adapters here....(assume row1 and row2 are in different tables and
    // i'm using 2 table adapters

    try
    {
    adapter1.Update( row1 );
    adapter2.Update( row2 );
    trans.Commit();
    }
    catch( Exception )
    {
    trans.Rollback();
    }
    }

    If the update completes successfuly on row1, but fails on row2, then even after the Rollback() call row1 will have a row state of Unchanged. So, since the problem is in row2, I fix the data in that row - it's rowstate is now modified, but row1's rowstate is still unchanged! Uh oh, this means that Update() will have no effect. How can I avoid this problem? I tried using BeginEdit() and EndEdit() and it didn't seem to work.

    Please let me know if you need more clarification.

    Thanks,
    Jordan


    Thursday, February 5, 2009 3:43 PM

Answers

  • When you call Update method of DataAdapter and row(s) saved successfully, it changes sate of those rows to Unchanged because of successful call. Transaction class does not have any effect of RowState property and does not roll state back. What you can do is to use SetAdded or SetModified methods of DataRow to change state of specific row.


    Val Mazur (MVP) http://www.xporttools.net
    • Marked as answer by Jordan1983 Friday, February 6, 2009 1:55 PM
    Friday, February 6, 2009 11:30 AM
    Moderator

All replies

  • When you call Update method of DataAdapter and row(s) saved successfully, it changes sate of those rows to Unchanged because of successful call. Transaction class does not have any effect of RowState property and does not roll state back. What you can do is to use SetAdded or SetModified methods of DataRow to change state of specific row.


    Val Mazur (MVP) http://www.xporttools.net
    • Marked as answer by Jordan1983 Friday, February 6, 2009 1:55 PM
    Friday, February 6, 2009 11:30 AM
    Moderator
  • That seems obvious now :) Thanks for the reply.

    - Jordan
    Friday, February 6, 2009 1:55 PM