ADO .NET Transactions rollback ( URGENT )

  • Thread starter João Santa Bárbara
  • Start date
J

João Santa Bárbara

Hi all
i have this problem .

i have 2 tables ( they are not master detail ) 2 simple tables, and i´m
doing a simple update just like this

try
Trans = Con.BeginTransaction
..........
DataAdpater1.Update(Table1) -> '10 rows Inserted in DataBase
DataAdapter2.Update(Table2) -> '10 rows Inserted in DataBase Sucess and
10 Unsucess

Trans.commit
cacth ex as exception
Trans.rollback
end try

Every Time i have an error i will run this code again ... and in the first
time i have done the rollback but in the second time all the records that
have been inserted ( in the first time ) are not inserted in the 2 time.
i saw all rows in the datatable and the row state is Unchanged when they
suposed to be Added ..

can someone help me .. ?

thks
JSB
 
W

W.G. Ryan MVP

The problem is that the data Adapter is calling acceptchanges on each row as
it's updated. It's actually by desing. In the 2.0 Framework, there's a data
adapter property called AcceptChangesDuringUpdate that you can set to
false, call your update, and where you call commit, call
DataSet.AcceptChanges.
http://www.knowdotnet.com/articles/acceptchangesduringupdate.html
http://msmvps.com/williamryan/archive/2004/07/10/9888.aspx

In the meantime you can use GetChanges

DataSet ds1 = Table1sDataSet.GetChanges();
DataSet ds2 = Table2DataSet.GetChanges();
try
{
da1.Update(ds1.Tables[0]);
da2.Update(ds2.Tables[0]);
Trans.Commit();
OriginalDataSet1.AcceptChanges();
OriginalDataSet2.AcceptChanges();
}
catch (SqlException ex)
{
foreach(SqlError er in ex.Errors){
//Build your error message
}
Trans.rollback();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top