Page 1 of 1

RejectChanges();

Posted: Fri 13 Jan 2006 21:29
by gala_l
I want insert in the table of the database some records, for example 10, which I have in the DataSet myDataSet, DataTable "MyTable"

myAdapter.Update(myDataSet, "myTable");
myDataSet.Tables["myTable"].AcceptChanges();
}
catch (Exception e)
{
myDataSet.Tables["myTable"].RejectChanges();
}

If I have exception situation in record 5, the first four records appeared in the database, but another 6 not. How can I do that if I try update DataSet, and catch exception, nothing appeared in the database? Why RejectChanges doesn't work?

Posted: Mon 16 Jan 2006 07:58
by SecureGen
AcceptChanges() method applies changes by DataRow. Thus successfully accepted DataRow becomes unchanged and it can not be rejected by RejectChanges().
In order to obtain behaviour that you expect, use DB transactions. Start new transaction before AcceptChanges() using following code:
PgSqlDirect tr = connection.BeginTransaction();
Then use:
tr.Commit();
after AcceptChanges() and
tr.Rollback();
after RejectChanges();

You can also try to use HasErrors property of DataTable. See example in the help on this property.