AutoIncrement With master detail relationship
Posted on 2006-11-15
I Have a Master Detail relationship where the Parent PK is an AutoIncrement field.
I am using a ADO 2.0 Dataset and i set the DataColumn's AutoIncrement and seed settings to -1, -1 so each new row gets added with a fake negative ID.
I then add a new Parent row and it gets an ID of -1, I then add Child row(s) and set the parent Id to -1.
I then attempt to save by calling the the dataAdapter.update (first on the parent and then on the child).
the parent row gets the new ID (the SQL command refershes the Data correctly) and the child row is even updated with the correct parent Id that was generated by the SQL server.
the problems now begin....
If i set the adapter.AcceptChangesDuringUpdate = true (before saving the parent table).
I call the adapter.update for the child table and It does not see any updated rows in the child table.
If i set the adapter.AcceptChangesDuringUpdate = false (before saving the parent table).
I call the adapter.update for the child table and it runs the Update command instead of the Insert command.
It seems the Update of the parent is changing the RowState of the child (the parentID is updated in the child row by the adapter), however since the child rowstate is added, any update to it should not change it's row state. (this row was never saved to the database, so any updates prior to the save it should remain in state added).