Insert (using windows forms) into multiple primary-foreign key related tables

ksh1337

New member
Joined
Oct 10, 2010
Messages
1
Programming Experience
Beginner
Hello everyone, so I've made tabs for the various tables, each tab having input fields for various attributes. Buttons on each tab-page to insert into the database for that particular table using table adapter, binding source and data set. All of there tables are related with one or more other tables. So when I run the application, whenever I input a field in the parent table and then hit the button, I get an exception saying that the same value should be there in child field. If I'm inserting into the "child" table first, the exception says that the parent table field cannot be null and so forth.

Also can I have the insert and update functionality in the same set of forms.

I know these forums would have gone through there doubts over multiple times in the past, but I have time-constraints :( really sorry.
 
Your description of the problem is not really quite precise enough. There's no issue with parent/child relationships as long as you do things correctly, so you obviously aren't but it's not possible to determine what the problem is from your general description. Please provide a full and precise description of the data, the relationships, what you're doing and what happens.

A good start would be the database you're using. I say that there's no issue with parent/child data but that's assuming a real database. If you're using Access then there is a problem with parent tables and Autonumber columns, because the auto-generated values can't be returned back to the application so the child records can't be updated before saving. This can lead to child records not being saved or, even worse, saved against the wrong parent.
 
Read this:
http://www.vbdotnetforums.com/datab...alling-endedit-causes-datarelations-fail.html

And read the DW4 link in my signature, section on Displaying Related Data and also Saving Related Data

You'll generally have to save the parents first, unless youre deleting a parent in a database that cannot cascade the delete, in which case you must delete the children first. You'll probably have to make sensible use of DataTable.GetChanges() passing in the relevant rowstate you want (i.e. deleted on the child, save em, deleted on the parent, save em, save everything that's left)
 
Back
Top