I have two tables, the first is the main one with a primary key called MaGV, the second has a field references to MaGV also called MaGV.
I create two datatables to store the corresponding data from the two tables in database.
After modifying the data in these two datatables, I start updating back to the two tables using adapter but there are two cases:
1.If using
DataTable.GetChanges()
like this:
adapter.Update(FirstDataTable.GetChanges();
adapter.Update(SecondDataTable.GetChanges());
A conflicted constraint exception will be thrown and I can understand it, just for the first Update couldn't do the update to the main Table and particularly the update should have added a new row to the table with MaGV = 1 (for example) but it didn't and there isn't any row with MaGV = 1 in the main Table.
Then the second Update, in my case, will insert a new row with MaGV = 1 into the second table and that of course will throw the exception.
2. If not using
DataTable.GetChanges()
, all the Updates will be done successfully, like this:
adapter.Update(FirstDataTable);
adapter.Update(SecondDataTable);
I can't understand why updating with
GetChanges()
can't be done well, it seems that
GetChanges()
returns null?
Could you please analyze the problem and give me any ideas?
Any of your helps are highly appreciated!
Thank you very much!