Parent-child + Datagrids

P

Patrick Huffer

I used the Data Form Wizard in Visual Studio to create a form allowing
the user to edit a simple parent table. The parent and child tables
already have a cascade updates relationship in SQL Server on the
parent table's primary key. I accepted all the defaults in the wizard.
A dataset was generated that contains the cascade update relationship.
The form that was generated contains two datagrids, a Load button, and
an Update button. Now, when I run the form and change the data in the
primary key column in the parent table, I get several strange things
happening. First there is a DBConcurrencyException when I try to
update, which occurs on the call to the second (child) dataset's
Update() method. The error reads: "Concurrency violation: the
UpdateCommand affected 0 records". But when I look at the data in SQL
Server, it has been correctly updated. So I think, OK, I can ignore
the concurrency violation error so I catch it and do nothing. This
time when I run the form and change the data in the primary key column
in the parent table, I get a ConstraintException: "Failed to enable
constraints. One or more rows contain values violating non-null,
unique or foreign-key constraints". And the parent table now displays
TWO identical rows, each with the new value that I just entered in the
primary key field. Again the data in both tables is totally correct.
At this point, I gave up.

My question is, under what circumstances can the Data Form Wizard
generate a form for two simple related tables that actually works? Is
there a tutorial out there anywhere that demonstates this?
 
P

Patrick Huffer

I wrote...
My question is, under what circumstances can the Data Form Wizard
generate a form for two simple related tables that actually works? Is
there a tutorial out there anywhere that demonstates this?

A follow up... I decided to not allow the user to update the primary
key of the parent table. To get around this, I added an identity field
and made that the primary key, and allow the user to update the Code
field (which used to be the primary key). Now everything works fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top