Parent-Child datagrids and FK Constraints


New member
May 20, 2005
Programming Experience
Here's the deal (simplified):

I have a Typed dataset with 2 tables Parent (ID, ParentName) and Child (ID, ParentID, ChildName). ParentID in Child is an FK (ParentChildFK) to the Parent table and is defined with cascase updating and deleting. The ID fields are defined as autoincrement with a step of -1 and a seed of -1.

On a Winodws Form, I have 2 datagrids dgMaster and dgDetail. dgMaster is bound to the Parent table and dgDetail is bound to the Parent table and the ParentChildFK datamember.

Adding/Updating rows in the grids works great as long as things are done in a certain order. If you:

1. Add a new row to the parent.
2. Add any child rows
3. Save.

it works just fine. The new child rows have the proper new ID's that were returned from the database during the data inserts.

However, if you:

1. Add a parent record
2. Save
3. Add a child row

you receive an error from the datagrid saying that the ForeignKeyConstraint was violated because the value, e.g. -1, does not exist in the parent table. The parent row now has a positive, actual ID, but the child grid or currecncy manager didn't seem to get the message that it should be using the new ID for any new rows.

Anyone have any ideas on how to resolve this?