I have 2 datatable In dataset object
TransactionReasons and TransactionSubReasons.
TransactionSubReasons datatable have foreignkey IDTransactionReason from TransactionReasons.
When I add new row to TransactionReasons(for example IDTransactionReason=1) and then adding new row to TransactionSubReasons. New added row's IDTransactionReason field equals to new added row's ID(in this example 1).Until this is every thing is good.
But when I want to update my database the problem is occured.
For updating I used tableAdapterManager.UpdateAll(MYDATSET);
How can i solve this problem?
Thank for your attention!开发者_运维技巧!!
So, what is this problem / exception exacly?
EDIT:
This exception suggest that you have an ADO.NET constraint associated with your relation (in addition to the DB constraint), but during update your child table rows don't receive the correct parent id. Maybe the tableAdapterManager tries to update the child table first?
I suggest you try to split this into 2 operations. That is:
Save the parent table (ensure in a separate program like SQL Management Studio that you got back the correct id's if they are auto generated
Save the child table (ensure that the parent id is set properly on newly added rows
You can use a debugger to see row fields after save.
If you wanted this two operations in a transaction, have a look here
精彩评论