|
-
February 6th, 2005, 06:40 PM
#1
Please help with rollback
Hi everybody!
I've got a problem with a dataset rollbacking.
Database Server is Sql Server.
And I use my own form for data changing.
So, this is the code of data record removing:
Code:
dataSetType.someTableRow activeRow = dataSet.someTable.FindBysome_id(id);
activeRow.Delete();
DataRow[] changedRows = dataSet.someTable.Select("", "", DataViewRowState.Deleted);
if (changedRows == null)
{
throw new Exception("no changes were detected in dataset");
}
if (Connection.State != ConnectionState.Open)
{
Connection.Open();
}
Transaction = Connection.BeginTransaction();
dataAdapter.DeleteCommand.Transaction = Transaction;
if (dataAdapter.Update(changedRows) == 0)
{
throw new Exception("no changes were detected in database after attempt to delete a record");
}
// here I throw my own exception for test
throw new Exception("");
dataSet.AcceptChanges();
Transaction.Commit();
MessageBox.Show("OK");
}
catch (Exception ex)
{
try
{
dataSet.RejectChanges();
}
catch {}
try
{
Transaction.Rollback();
}
catch {}
MessageBox.Show(ex.ToString());
}
finally
{
try
{
Transaction.Dispose();
}
catch {}
try
{
Connection.Close();
}
catch {}
}
the problem is than if any exceptions occure after update command like in the given example, then no data is passed to database, but the record I've delete is removed from dataset. If I comment the statement with Update command of DataAdapter, then everything works fine, I mean that record gets back after it was deleted. How to resolve that problem?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|