RejectChanges();

RejectChanges();

Postby gala_l » Fri 13 Jan 2006 21:29

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?
gala_l
 

Postby SecureGen » Mon 16 Jan 2006 07:58

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.
SecureGen
Devart Team
 
Posts: 133
Joined: Thu 08 Sep 2005 06:27


Return to dotConnect for PostgreSQL