I have a parent-child relation setup between two tables. The parent table is setup with an auto increment value for its primary key. This is working fine and the new row in the parent DataTable is refreshed with the actual value of the key that was just inserted when I call Update on the TableAdaptor.
The problem is that the rows from the child table are not being inserted into the DB. For debug purposes, I added changesBefore and changesAfter to the code sample to see what changed rows exist in the child table. When I step through the code with a debugger, changesBefore constains the new child rows. changesAfter is Nothing. Its almost as if calling Update against the header table is triggering AcceptChanges on the child table.
I am familiar with insert/updating with DataTables and TableAdapters but this is my first attempt at using an autoincrement on a parent table. What am I missing here?
Dim changesBefore = _ds.ResponseDetails.GetChanges
headersTa.Update(_ds.ResponseHeaders)
Dim changesAfter = _ds.ResponseDetails.GetChanges
detailsTa.Update(_ds.ResponseDetails)
This is working now. Turns out there is an
AcceptRejectRuleproperty for each relation in a data set. I had the rule set toCascadeso it was basically cascadingAcceptChangesdown to the child table whenUpdatewas called against the parent. Changing the rule toNoneresolved my issue.http://msdn.microsoft.com/en-us/library/system.data.acceptrejectrule(v=vs.80).aspx