Hey everyone,
I have 3 tables in an Access database - tblMain, tblDelivery, and tblOtherCosts. tblMain is the parent table with a primary key (ID) and tblDelivery and tblOtherCosts are detail tables with foreign keys (ID) in a one to many relationship with tblMain. Update and delete events are set to cascade (via Dataset Designer in
VB 2008).
I display data from all three tables on a form: I have a DataGridView bound to tblMain. tblDelivery and tblOtherCosts have their respective textboxes (bound to the appropriate fields) on the form. tblMain also has a DataNavigator on the form.
I fill the dataset with:
Me.TblOtherCostsTableAdapter.Fill(Me.SpDataSet.tbl OtherCosts)
Me.TblDeliveryTableAdapter.Fill(Me.SpDataSet.tblDe livery)
Me.TblMainTableAdapter.Fill(Me.SpDataSet.tblMain)
To save changes to the database, I use the following:
Private Sub TblMainBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TblMainBindingNavigatorSaveItem.Click
Me.Validate()
Me.TblMainBindingSource.EndEdit()
Me.TblDeliveryBindingSource.EndEdit()
Me.TblOtherCostsBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.SpDataSet)
End Sub
If I edit a value in the databound text box for tblDelivery or tblOtherCosts and try to save it (update) I get "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records". Does anyone know why this is, and how I should modify my code to fix it?