T
Tony K
VB 2005.
I receive the error, "You cannot add or change a record because a related
record is required in table 'Purchase Orders'."
In my form, the parent record Purchase Orders is in details view. The child
record(s) is in GridView.
Table: Purchase Orders fields:
PK - PurchaseOrderID
PurchaseOrderNumber
PurchaseOrderDescription
SupplierID ->Relation Only to Suppliers Table
EmployeeID -> Relation Only to Employees Table
OrderDate
DateRequired
ShipDate
ShippingMethodID -> Relation Only to Shipping Table
FreightCharge
PurchaseOrderClosed
DateReceived
Table: Inventory Transactions fields
PK - TransactionID
TransactionDate
ProductID -> Relation Only to Products Table
PurchaseOrderID -> Relation Only to Purchase Orders Table
TransactionDescription
UnitPrice
UnitsOrdered
UnitsReceived
UnitsSold
UnitsShrinkage
Equipment -> Relation Only to Equipment Table
********ALL FIELDS EXCEPT PRIMARY KEYS ALLOW DBNULL VALUES*************
With the Purchase Orders Table empty, when I create the very first record, I
receive the error message above. If I EXIT the program and re-enter, the
parent table info is there (Purchase Orders info) but the Inventory
Transactions info is missing. If I then re-enter the Inventory Transactions
in the DataGridView, it will save.
I have now run into the same problem but NO WORK-AROUND. I have hard coded
the info into a completely different form (really sloppy I'm sure) but I get
the same results. The code is below and I have marked where the error
occurs.
Dim row As DataGridViewRow
Dim cmmInvMan As OleDbCommand
Dim strSQL As String
Dim drdTest As OleDbDataReader
Dim recordCounter As Integer = 999990
Dim cnnInvMan As OleDbConnection = New
OleDbConnection(My.Settings.Inventory_management_databaseConnectionString)
cnnInvMan.Open()
Dim supplierID As Integer, productID As Integer, poID As Integer
Dim supplier As String = "", productDescription As String = ""
supplier =
CStr(Me.POGenerateDataGridView.Rows(0).Cells("SupplierName").Value)
strSQL = "SELECT SupplierID FROM Suppliers WHERE SupplierName = '" &
supplier & "'"
cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
supplierID = CInt(drdTest.Item(0))
Loop
Me.Purchase_OrdersTableAdapter.Insert(recordCounter.ToString,
Nothing, supplierID, Nothing, Date.Today(), Today.AddDays(5), Nothing,
Nothing, Nothing, False, Nothing)
Me.Purchase_OrdersTableAdapter.Update(Me.Inventory_management_databaseDataSet)
For Each row In POGenerateDataGridView.Rows
'supplier = CStr(row.Cells("SupplierName").Value)
'MessageBox.Show("Supplier = " & supplier & vbCrLf & "Row count
= " & Me.POGenerateDataGridView.Rows.Count.ToString, "Test")
If supplier <> row.Cells("SupplierName").Value.ToString Then
Exit For
End If
strSQL = "SELECT * FROM Products WHERE ProductIDNumber = '" &
row.Cells("ProductIDNumber").Value.ToString & "'"
cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
productID = CInt(drdTest.Item("ProductID"))
productDescription =
CStr(drdTest.Item("ProductDescription"))
Loop
strSQL = "SELECT PurchaseOrderID FROM [Purchase Orders] WHERE
PurchaseOrderID = " & recordCounter.ToString
cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
poID = CInt(drdTest.Item(0))
Loop
'*********************ERROR OCCURS AT THE INSERT STATEMENT
BELOW*************
Me.Inventory_TransactionsTableAdapter.Insert(Date.Today(),
productID, poID, productDescription, Nothing, _
Nothing, Nothing, Nothing, Nothing,
Nothing)
supplier = row.Cells("SupplierName").Value.ToString
Next
The insert statement for the Access DB is:
INSERT INTO `Inventory Transactions` (`TransactionDate`, `ProductID`,
`PurchaseOrderID`, `TransactionDescription`, `UnitPrice`, `UnitsOrdered`,
`UnitsReceived`, `UnitsSold`, `UnitsShrinkage`, `Equipment`) VALUES (?, ?,
?, ?, ?, ?, ?, ?, ?, ?)
Thanks to all,
Tony K
I receive the error, "You cannot add or change a record because a related
record is required in table 'Purchase Orders'."
In my form, the parent record Purchase Orders is in details view. The child
record(s) is in GridView.
Table: Purchase Orders fields:
PK - PurchaseOrderID
PurchaseOrderNumber
PurchaseOrderDescription
SupplierID ->Relation Only to Suppliers Table
EmployeeID -> Relation Only to Employees Table
OrderDate
DateRequired
ShipDate
ShippingMethodID -> Relation Only to Shipping Table
FreightCharge
PurchaseOrderClosed
DateReceived
Table: Inventory Transactions fields
PK - TransactionID
TransactionDate
ProductID -> Relation Only to Products Table
PurchaseOrderID -> Relation Only to Purchase Orders Table
TransactionDescription
UnitPrice
UnitsOrdered
UnitsReceived
UnitsSold
UnitsShrinkage
Equipment -> Relation Only to Equipment Table
********ALL FIELDS EXCEPT PRIMARY KEYS ALLOW DBNULL VALUES*************
With the Purchase Orders Table empty, when I create the very first record, I
receive the error message above. If I EXIT the program and re-enter, the
parent table info is there (Purchase Orders info) but the Inventory
Transactions info is missing. If I then re-enter the Inventory Transactions
in the DataGridView, it will save.
I have now run into the same problem but NO WORK-AROUND. I have hard coded
the info into a completely different form (really sloppy I'm sure) but I get
the same results. The code is below and I have marked where the error
occurs.
Dim row As DataGridViewRow
Dim cmmInvMan As OleDbCommand
Dim strSQL As String
Dim drdTest As OleDbDataReader
Dim recordCounter As Integer = 999990
Dim cnnInvMan As OleDbConnection = New
OleDbConnection(My.Settings.Inventory_management_databaseConnectionString)
cnnInvMan.Open()
Dim supplierID As Integer, productID As Integer, poID As Integer
Dim supplier As String = "", productDescription As String = ""
supplier =
CStr(Me.POGenerateDataGridView.Rows(0).Cells("SupplierName").Value)
strSQL = "SELECT SupplierID FROM Suppliers WHERE SupplierName = '" &
supplier & "'"
cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
supplierID = CInt(drdTest.Item(0))
Loop
Me.Purchase_OrdersTableAdapter.Insert(recordCounter.ToString,
Nothing, supplierID, Nothing, Date.Today(), Today.AddDays(5), Nothing,
Nothing, Nothing, False, Nothing)
Me.Purchase_OrdersTableAdapter.Update(Me.Inventory_management_databaseDataSet)
For Each row In POGenerateDataGridView.Rows
'supplier = CStr(row.Cells("SupplierName").Value)
'MessageBox.Show("Supplier = " & supplier & vbCrLf & "Row count
= " & Me.POGenerateDataGridView.Rows.Count.ToString, "Test")
If supplier <> row.Cells("SupplierName").Value.ToString Then
Exit For
End If
strSQL = "SELECT * FROM Products WHERE ProductIDNumber = '" &
row.Cells("ProductIDNumber").Value.ToString & "'"
cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
productID = CInt(drdTest.Item("ProductID"))
productDescription =
CStr(drdTest.Item("ProductDescription"))
Loop
strSQL = "SELECT PurchaseOrderID FROM [Purchase Orders] WHERE
PurchaseOrderID = " & recordCounter.ToString
cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
poID = CInt(drdTest.Item(0))
Loop
'*********************ERROR OCCURS AT THE INSERT STATEMENT
BELOW*************
Me.Inventory_TransactionsTableAdapter.Insert(Date.Today(),
productID, poID, productDescription, Nothing, _
Nothing, Nothing, Nothing, Nothing,
Nothing)
supplier = row.Cells("SupplierName").Value.ToString
Next
The insert statement for the Access DB is:
INSERT INTO `Inventory Transactions` (`TransactionDate`, `ProductID`,
`PurchaseOrderID`, `TransactionDescription`, `UnitPrice`, `UnitsOrdered`,
`UnitsReceived`, `UnitsSold`, `UnitsShrinkage`, `Equipment`) VALUES (?, ?,
?, ?, ?, ?, ?, ?, ?, ?)
Thanks to all,
Tony K