We have a DataSet with parent/child relations set up. We have a BindingSource and a BindingNavigator configured for each table. When we use the BindingNavigator for the child table to add a new record (click the Add button...) the foreign key value in the child table is not getting filled in. When we call EndEdit on the BindingSource we are getting an exception because this field does not allow nulls in the DataSet.
The relationship between the tables is just like Order/OrderDetails where the OrderDetails table has a PK column (OrderDetailsID) and an FK column (OrderID).
First of all, if we have things configured right between the tables the OrderID column in the child table is supposed to be filled in automatically with the value of the ID in the current row in the parent table, right
If this *is* supposed to happen automatically, what is the checklist of things that must be configured properly for this to happen
Thanks.

Adding a row to a child table
gazwik
I am having the same sort of problem and thought I would reinitiate this thread as it doesnt look like a final solution has been provided.
I have a simple 'one-to-many' data relationship which I have established using the VS 2005 designer. I am using a tab control to seperate the Master/Parent table from the Detail/Child table. When I click on the Detail tab, my form correctly populates all the appropriate detail records into all all the relevant bound controls (text boxes/comboboxes). It even includes the correct Foreign Key value (which is bound to the Foreign Key Field of my binding source). So, everything seems to work splendidly except for the fact that when I go look at the backend database (MS Access) the Foreign Key of my Child table is not being entered into my database! It just uses the default value of 0 for every detail record I have entered. I cant figure out why it is not populating correctly. Does anyone have an idea what I may doing wrong
Thanks!!!
Mike
RVlem
I've got it figured out. You have to have the following in place for this to work right:
Once you have those things in place, and use the BindingSource to add rows to the DataSet, the FK values get filled in automatically (provided you don't disable constraints or whatever).
Mark Kornfein
myoungbl
Thanks for following up with the information you found.
David Sceppa
ADO.NET Program Manager
Microsoft
Thomas Pyndt
OK, I have an answer to my problem, sort of..... After much frustration, I just deleted all me datasets in my project and reimported my Access database. Visual Studio recreated all my tables and relations etc, and everything worked as it should have.
I believe I must of made some changes in my Access database that didnt jive with the designer in VS although I was never getting an error, it just didnt work. Just thought I would update this post in the event somebody else ran into this problem
Mike
viswaug
I am trying to do the same thing in VB2005 and getting no where. I have set up a situation that basically follows the before mentioned scenario. When I press the add button on the navigator a new record is created for the parent table but not the child table. I have tried explicitly doing an addnew on the child binding source. It looks like it creates a new record but byt the time I press the save button the row count is zero.
I feel like I am missing a basic assumption. Is it correct to assume that doing an addnew on the parent binding source is supposed to automagically create a child record
Thanks!
JohnArlen
Well this seems to work but it doesn't seem very elegant. I still think I'm missing something...
Private Sub Parent_textTextBox_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Parent_textTextBox.Leave Me.Parent1BindingSource.EndEdit() If Child2BindingSource.Current Is Nothing Then Me.Child2BindingSource.AddNew() End If Me.Child2BindingSource.ResetCurrentItem() End Sub