M
Mark Tompkins
Gents -
I have a DataSet with a Parent / Child relation.
On Form1 I have a DGV that is bound to the details (child) portion of the
relation (tblInventoryTransBindingSource).
I have a BindingNavigator bound to the Parent binding source (tblPurchaseOrdersBindingSource).
On the form I also have a DateTimePicker for date control bound to tblPurchaseOrdersBindingSource
- OrderDate.
In order to create a default value of today on the DateTimePicker control,
I have set the BindingNavigator's "AddNewItem" to NONE to handle this programmatically.
I have the following code:
<code>
Private Sub POAddNewItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles BindingNavigatorAddNewItem.Click
Me.TblPurchaseOrdersBindingSource.AddNew()
Me.OrderDateDateTimePicker.Value = DateTime.Today
End Sub
</code>
That works fine.
The problem I am running into is on the entering of data to a new child record.
When I click AddNew of the binding nav new record data on the parent is
started and the first line of entry on the DGV appears. As I enter data on
the child (DGV) on row one it enters without issue but as I move to row 2
(next new row) an exception is thrown:
System.Data.InvalidConstraintException: ForeignKeyConstraint FK_tblInvTrans_tblPurchaseOrders
requires the child key values (1) to exist in the parent table.
So it seems I need to get that primary key generated into the Master record
(tblPurchaseOders) prior to entering data into the DGV.
I have tried some of the following code to no avail -
<code>
' Trying to save the Parent PO data prior to editing the DGV
' Those listed below did not make this happen
'Me.TblInvTransTableAdapter.Update(Me.PODataSet.tblInvTrans)
'Me.TblPurchaseOrdersTableAdapter.GetData()
'Me.TblPurchaseOrdersTableAdapter.Fill(Me.PODataSet.tblPurchaseOrders)
'Me.TblInvTransTableAdapter.GetData()
'Me.TblPurchaseOrdersTableAdapter.Update(Me.PODataSet.tblPurchaseOrders)
'Me.PODataSet.AcceptChanges()
'Me.TblPurchaseOrdersTableAdapter.Fill(Me.PODataSet.tblPurchaseOrders)
</code>
Which are my efforts of pushing this autoincrement key back up to the parent
and refreshing the DGV.
I have tried setting the fields: AutoIncrementSeed =-1, AutoIncrementStep=-1
to try and let the DataSet handle it.
Again no luck.
Help in the appropriate way to handle this would be appreciated.
Many thanks,
Mark
I have a DataSet with a Parent / Child relation.
On Form1 I have a DGV that is bound to the details (child) portion of the
relation (tblInventoryTransBindingSource).
I have a BindingNavigator bound to the Parent binding source (tblPurchaseOrdersBindingSource).
On the form I also have a DateTimePicker for date control bound to tblPurchaseOrdersBindingSource
- OrderDate.
In order to create a default value of today on the DateTimePicker control,
I have set the BindingNavigator's "AddNewItem" to NONE to handle this programmatically.
I have the following code:
<code>
Private Sub POAddNewItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles BindingNavigatorAddNewItem.Click
Me.TblPurchaseOrdersBindingSource.AddNew()
Me.OrderDateDateTimePicker.Value = DateTime.Today
End Sub
</code>
That works fine.
The problem I am running into is on the entering of data to a new child record.
When I click AddNew of the binding nav new record data on the parent is
started and the first line of entry on the DGV appears. As I enter data on
the child (DGV) on row one it enters without issue but as I move to row 2
(next new row) an exception is thrown:
System.Data.InvalidConstraintException: ForeignKeyConstraint FK_tblInvTrans_tblPurchaseOrders
requires the child key values (1) to exist in the parent table.
So it seems I need to get that primary key generated into the Master record
(tblPurchaseOders) prior to entering data into the DGV.
I have tried some of the following code to no avail -
<code>
' Trying to save the Parent PO data prior to editing the DGV
' Those listed below did not make this happen
'Me.TblInvTransTableAdapter.Update(Me.PODataSet.tblInvTrans)
'Me.TblPurchaseOrdersTableAdapter.GetData()
'Me.TblPurchaseOrdersTableAdapter.Fill(Me.PODataSet.tblPurchaseOrders)
'Me.TblInvTransTableAdapter.GetData()
'Me.TblPurchaseOrdersTableAdapter.Update(Me.PODataSet.tblPurchaseOrders)
'Me.PODataSet.AcceptChanges()
'Me.TblPurchaseOrdersTableAdapter.Fill(Me.PODataSet.tblPurchaseOrders)
</code>
Which are my efforts of pushing this autoincrement key back up to the parent
and refreshing the DGV.
I have tried setting the fields: AutoIncrementSeed =-1, AutoIncrementStep=-1
to try and let the DataSet handle it.
Again no luck.
Help in the appropriate way to handle this would be appreciated.
Many thanks,
Mark