problem adding child records

T

Tony Martini

Hello all
I have a VB.Net Windows Forms application that is using bound controls. I
have datarelations defined for the parent and child tables with the Update,
Delete and accept/reject rules all set to default ( which is cascade). I can
modify and delete records. I can add records to the parent table as long as
I am not also adding child records. When I add a parent record and add a
record to the grid bound to the child table I get an error stating that the
row id must exist in the parent table. I do not want to remove the
constraints so how do I allow users to add a parent record and a child
record in one session.. I call parentdataadapter.update first then
childdataadapter.update. I thought this would add the parent records then
the child records. If I set dataset.enforceconstraints = false before
calling dataset.addnew it does not give me an error when I exit the grid but
it does not insert the child records.
 
D

David Sceppa

Tony,

It sounds like the parent row still hasn't been added to the parent
DataTable. How are you adding the parent row? You'll need to implicitly
commit the row to the DataTable by moving to another row, or by explicitly
calling the EndEdit method on the CurrencyManager.

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2004 Microsoft Corporation. All rights reserved.
 
T

Tony Martini

David,
The problem was that the parent row was not committed to the database. I
called AcceptChanges after the call to Update for the parent row and was
then able to update the child tables successfully. Thanks for the post.
Tony
 

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