Hello everyone,
I’m hoping someone in the DaniWeb community can help me. I have a VB 2005 project to complete. I have two related tables called CurrentInventory (which is the parent table) and a child table called TrackingInventory. I want to update an existing row in the dataset for the CurrentInventory table for the Quanity_on_hand field. It works just fine while it’s still disconnected from the dataset. However, when I try to update the dataset it either doesn’t update in the table or I if I leave out the acceptchanges method for the table and try to save I get an error message:
The record cannot be deleted or changed because table 'TrackingInventory' includes related records.
I also tried deleting the exiting datarow in the dataset and adding a new row with updates to the Quantity_on_hand field but I get an error message saying this row already exists in the table.
Here is the code:
Private Sub updateCurrentInventory()
Dim dsCurrentInventoryEditRow As DataRow
Dim saveIndex As Integer
Dim myobject As Object
saveIndex = Me.genderDatagrid.CurrentRowIndex
dsCurrentInventoryEditRow = aFirstShoeFundDataSet.Tables("CurrentInventory").Rows(saveIndex)
myobject = dsCurrentInventoryEditRow.Item("Quantity_on_hand")
If myobject Is DBNull.Value Then
myobject = 0
End If
dsCurrentInventoryEditRow.Item("Gender") = genderColumnString
If addingBoolean = True Then
myobject = CType(myobject, Integer) + myUpdateInventoryInteger
dsCurrentInventoryEditRow.Item("Quantity_on_hand") = myobject
ElseIf removeButtonBoolean = True Then
myobject = CType(myobject, Integer) - myUpdateInventoryInteger
dsCurrentInventoryEditRow.Item("Quantity_on_hand") = myobject
End If
aFirstShoeFundDataSet.Tables("CurrentInventory").Rows(saveIndex)("Quantity_on_hand") = myobject
aFirstShoeFundDataSet.Tables("CurrentInventory").AcceptChanges()
End Sub