Paul P
Member
Hi
I greatly appreciate some help, I'm sure this should be simple!
I'm trying to make a simple data entry form to create a new Contact (parent) and one new Location (child).
The design is:
- Tables are in SQLServer. Contacts table (parent) and Locations table (child)
- Relation and Foreign Key Constraint in place at database and dataset level.
- Update and Delete Rule = Cascade.
- Using Table AdapterManager.UpdateAll
When I do this using a simple form with 2 x DataGridViews it works as expected. It backfills the Parent primary key to the Child etc. All fine!
If I use exactly the same project, but swap out the DataGridViews for a 'Details' view, created by dragging from the DataSources, it does not work.
- When I 'Add New' it clears all the text boxes in Parent and Child fields, and inserts temporary Primary Key in both = -1.
- When I 'Save', it saves the Parent Record successfully, but does not save the Child. It just clears all the child fields including the temporary primary key
I have broken the code down and the problem is that when the .endedit is called on the parent table -> it clears the Locations (child) details.
I have trawled the net and found lots of threads that describe exactly this problem going back many years. But, I haven't found an explanation on how to get it to work yet.
I am sure this will turn out to be straight forward!
Really appreciate some help.
Cheers
PP
I greatly appreciate some help, I'm sure this should be simple!
I'm trying to make a simple data entry form to create a new Contact (parent) and one new Location (child).
The design is:
- Tables are in SQLServer. Contacts table (parent) and Locations table (child)
- Relation and Foreign Key Constraint in place at database and dataset level.
- Update and Delete Rule = Cascade.
- Using Table AdapterManager.UpdateAll
When I do this using a simple form with 2 x DataGridViews it works as expected. It backfills the Parent primary key to the Child etc. All fine!
If I use exactly the same project, but swap out the DataGridViews for a 'Details' view, created by dragging from the DataSources, it does not work.
- When I 'Add New' it clears all the text boxes in Parent and Child fields, and inserts temporary Primary Key in both = -1.
- When I 'Save', it saves the Parent Record successfully, but does not save the Child. It just clears all the child fields including the temporary primary key
I have broken the code down and the problem is that when the .endedit is called on the parent table -> it clears the Locations (child) details.
I have trawled the net and found lots of threads that describe exactly this problem going back many years. But, I haven't found an explanation on how to get it to work yet.
I am sure this will turn out to be straight forward!
Really appreciate some help.
Cheers
PP
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.ContactsTableAdapter.Fill(Me.DataSet1.Contacts) Me.LocationsTableAdapter.Fill(Me.DataSet1.Location s) End Sub Private Sub AddNewButton_Click(sender As Object, e As EventArgs) Handles AddNewButton.Click Me.ContactsBindingSource.AddNew() Me.LocationsBindingSource.AddNew() End Sub Private Sub ContactsBindingNavigatorSaveItem_Click_1(sender As Object, e As EventArgs) Handles ContactsBindingNavigatorSaveItem.Click Me.Validate() Me.ContactsBindingSource.EndEdit() Me.LocationsBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.DataSet1) End Sub
Last edited by a moderator: