T
Tony K
I know I have asked a lot of questions here, but this one might puzzle
others.
I have a query that gets all products whose OnHand < MinRequired and grouped
by the supplier. The query fills perfectly.
From that, I autogenerate a Purchase Order and for each supplier, I add the
associated products.
When I execute the program without breakpoints, all the products are added
to the first created purchase order even though the products do not belong
to that supplier. Then, the other PO's are created but no products are
filled for the remaining suppliers.
IF I create a breakpoint where the supplier has changed, then continue, the
appropriate PO's are created with the correct products for each supplier.
Help, I don't know what is going on.
Entire GeneratePO_Click Routine:
***BEGINNING
Dim row As DataGridViewRow
Dim cmmInvMan As OleDbCommand
Dim strSQL As String
Dim maximumOnHand As Integer, unitsOrdered As Integer
Dim drdTest As OleDbDataReader
Dim recordCounter As Integer = 999990 'Temporary PO #
Dim cnnInvMan As OleDbConnection = New
OleDbConnection(My.Settings.Inventory_management_databaseConnectionString)
cnnInvMan.Open()
Dim supplierID As Integer, productID As Integer, price As Decimal
Dim supplier As String = "", productDescription As String = "", poID
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, "Auto
Generated PO", 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
If supplier <> row.Cells("SupplierName").Value.ToString Then
'***If Supplier is different
supplier = CStr(row.Cells("SupplierName").Value) '***If I
perform breakpoint here...IT WORKS.
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
recordCounter += 1 'Increment Temporary PO# for new PO.
Me.Purchase_OrdersTableAdapter.Insert(recordCounter.ToString,
"Auto Generated PO", supplierID, _
Nothing, Date.Today(), Today.AddDays(5),
Nothing, Nothing, Nothing, False, Nothing)
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"))
maximumOnHand = CInt(drdTest.Item("MinimumRequired"))
price = CDec(drdTest.Item("UnitPrice"))
Loop
strSQL = "SELECT SUM(UnitsReceived) - SUM(UnitsSold) -
SUM(UnitsShrinkage) " & _
"FROM [Inventory Transactions]" & _
"WHERE (ProductID = " & productID & ")"
cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
unitsOrdered = maximumOnHand - CInt(drdTest.Item(0))
Loop
cmmInvMan.Dispose()
drdTest.Close()
strSQL = "SELECT * FROM [Purchase Orders] WHERE
PurchaseOrderNumber = '" & recordCounter.ToString & "'"
cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
poID = CStr(drdTest.Item("PurchaseOrderID"))
Loop
Me.Inventory_TransactionsTableAdapter.Insert(Date.Today(),
productID, CType(poID, Integer), productDescription, price, _
unitsOrdered, Nothing, Nothing, Nothing,
Nothing)
Next
*****END
Thanks,
Tony K.
others.
I have a query that gets all products whose OnHand < MinRequired and grouped
by the supplier. The query fills perfectly.
From that, I autogenerate a Purchase Order and for each supplier, I add the
associated products.
When I execute the program without breakpoints, all the products are added
to the first created purchase order even though the products do not belong
to that supplier. Then, the other PO's are created but no products are
filled for the remaining suppliers.
IF I create a breakpoint where the supplier has changed, then continue, the
appropriate PO's are created with the correct products for each supplier.
Help, I don't know what is going on.
Entire GeneratePO_Click Routine:
***BEGINNING
Dim row As DataGridViewRow
Dim cmmInvMan As OleDbCommand
Dim strSQL As String
Dim maximumOnHand As Integer, unitsOrdered As Integer
Dim drdTest As OleDbDataReader
Dim recordCounter As Integer = 999990 'Temporary PO #
Dim cnnInvMan As OleDbConnection = New
OleDbConnection(My.Settings.Inventory_management_databaseConnectionString)
cnnInvMan.Open()
Dim supplierID As Integer, productID As Integer, price As Decimal
Dim supplier As String = "", productDescription As String = "", poID
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, "Auto
Generated PO", 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
If supplier <> row.Cells("SupplierName").Value.ToString Then
'***If Supplier is different
supplier = CStr(row.Cells("SupplierName").Value) '***If I
perform breakpoint here...IT WORKS.
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
recordCounter += 1 'Increment Temporary PO# for new PO.
Me.Purchase_OrdersTableAdapter.Insert(recordCounter.ToString,
"Auto Generated PO", supplierID, _
Nothing, Date.Today(), Today.AddDays(5),
Nothing, Nothing, Nothing, False, Nothing)
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"))
maximumOnHand = CInt(drdTest.Item("MinimumRequired"))
price = CDec(drdTest.Item("UnitPrice"))
Loop
strSQL = "SELECT SUM(UnitsReceived) - SUM(UnitsSold) -
SUM(UnitsShrinkage) " & _
"FROM [Inventory Transactions]" & _
"WHERE (ProductID = " & productID & ")"
cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
unitsOrdered = maximumOnHand - CInt(drdTest.Item(0))
Loop
cmmInvMan.Dispose()
drdTest.Close()
strSQL = "SELECT * FROM [Purchase Orders] WHERE
PurchaseOrderNumber = '" & recordCounter.ToString & "'"
cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
poID = CStr(drdTest.Item("PurchaseOrderID"))
Loop
Me.Inventory_TransactionsTableAdapter.Insert(Date.Today(),
productID, CType(poID, Integer), productDescription, price, _
unitsOrdered, Nothing, Nothing, Nothing,
Nothing)
Next
*****END
Thanks,
Tony K.