Database Exception Error

T

Tony K

When rebuilding my inventory application it creates a new empty copy of the
Access DB. When creating the first record of my purchase order screen which
has a related table 'Inventory Transactions' as a DataGrid, I receive this
error.

Notes: Drag and Drop used from Data Sources window. Purchase Order in
details view. Inventory Transactions in grid view.

System.Data.OleDb.OleDbException: You cannot add or change a record because
a related record is required in table 'Purchase Orders'. at
......etc.etc.etc.

If I close the form and reopen, the PO record is there, but the Inventory
Transactions data is not there. If I re-enter the Inventory Transactions
data in the grid, everything saves perfectly.

My 'Save' routine is below.


Private Sub Purchase_OrdersBindingNavigatorSaveItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Purchase_OrdersBindingNavigatorSaveItem.Click, SaveToolStripMenuItem.Click
Try
Cursor = Cursors.WaitCursor
Me.Validate()
Me.Purchase_OrdersBindingSource.EndEdit()
Me.Inventory_TransactionsBindingSource.EndEdit()
Me.Purchase_OrdersTableAdapter.Update(Me.Inventory_management_databaseDataSet.Purchase_Orders)
Me.Inventory_TransactionsTableAdapter.Update(Me.Inventory_management_databaseDataSet.Inventory_Transactions)
Me.StatusToolStripStatusLabel.Text = Nothing
Catch ex As Exception
MessageBox.Show(ex.ToString, "Error Saving Purchase Order",
MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
Finally
Cursor = Cursors.Default
End Try
End Sub

How do I debug something like this???

Thanks,
Tony K.
 
C

Cor Ligthert[MVP]

Tony,

This is hard to debug, however probably it is because that you do the update
in the way as all newbies do. You have to synchronise the update yourself.

At the moment I have no simple sample at hand. However you have first to do
the rows from the parent tables in the update in the sequenc: New, Changed
and then the Deleted. After that the child tables. You use for that the
GetChanges while the datarowstate has to match the datarowstate enum, while
you update the collected rows. (Be aware that those are just references) At
the end you do an acceptchanges of the original table.

Cor
 

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