F
Flomo Togba Kwele
I get an error when executing the Update method on a dataset. The dataset is a
strongly typed one, with two tables in a parent/child relationship.
The parent has an identity column for its PK, while the child's PK is a
composite one. Its first column is the identity column of the parent and the
other column is a zipcode.
There is a constraint in the child:
ALTER TABLE Child ADD CONSTRAINT FK_Rel FOREIGN KEY(ParentPK)
REFERENCES Parent (ParentPK)
During processing, I allow the user to create a new Parent row and change any
of the child rows so that its new parent is the newly added Parent row. I set
these Child rows's foreign key column to match the value of the identity column
of the newly added Parent row.
I don't know how this value gets assigned to the newly added Parent, but this
value does not exist in the live DB. When I look at the identity columns in
both the Parent and Child rows in the debugger before the Update method is
executed, I see that they have the same value.
When the Update method executes, I receive the following error:
The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_Rel". The
conflict occurred in database "MailHaus", table "dbo.Parent", column 'ParentPK'.
The statement has been terminated.
What do I need to do to clean this up? I am totally confused. I don't see how
cascading updates would help the situation, since I'm not asking the parent to
propagate its changes to its children - it's the opposite.
Thanks, Flomo
strongly typed one, with two tables in a parent/child relationship.
The parent has an identity column for its PK, while the child's PK is a
composite one. Its first column is the identity column of the parent and the
other column is a zipcode.
There is a constraint in the child:
ALTER TABLE Child ADD CONSTRAINT FK_Rel FOREIGN KEY(ParentPK)
REFERENCES Parent (ParentPK)
During processing, I allow the user to create a new Parent row and change any
of the child rows so that its new parent is the newly added Parent row. I set
these Child rows's foreign key column to match the value of the identity column
of the newly added Parent row.
I don't know how this value gets assigned to the newly added Parent, but this
value does not exist in the live DB. When I look at the identity columns in
both the Parent and Child rows in the debugger before the Update method is
executed, I see that they have the same value.
When the Update method executes, I receive the following error:
The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_Rel". The
conflict occurred in database "MailHaus", table "dbo.Parent", column 'ParentPK'.
The statement has been terminated.
What do I need to do to clean this up? I am totally confused. I don't see how
cascading updates would help the situation, since I'm not asking the parent to
propagate its changes to its children - it's the opposite.
Thanks, Flomo