|
-
Sep 26th, 2006, 09:51 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] DB Returning No Results
Good Morning,
I posted this question in the VB.NET forum, but it looks as though I posted it to the wrong audience. I have used the structure of the code below successfully in past subs. However, this particular sub will not return values even though they exist. I am attempting to connect to table invMain in an Access Database and locate a value in the Inventory column where the PartNumber column = a value pulled from an array.
Code:
Sub CheckForSufficientInventory(ByRef proceed As Boolean, ByRef bomList As ArrayList, _
ByRef qtyList As ArrayList)
' CHECK ARRAYLIST AGAINST INVENTORY
' PROCEED IF SUFFICIENT INVENTORY OR
' NOTIFY USER OF DEFICIENCIES
' GIVE OPTION TO OVERRIDE
Dim buildQty As Integer
Dim canBuild As Integer
Dim currentItem As String
Dim currentQty As Integer
Dim invQty As Integer
Dim itemNumber As Integer
Dim itemsShort As Integer
Dim totalCanBuild As Integer = buildQty
Dim selectString As String
Try
' CREATE CONNECTION AND OPEN
Dim invConString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data " & _
"Source=C:\******.mdb;" & _
"Jet OLEDB:Database Password=******;"
invCon = New OleDbConnection(invConString)
invCon.Open()
' CHECK INVENTORY
For itemNumber = 1 To bomList.Count
' SET CURRENT ITEM AND QTY
currentItem = bomList.Item(itemNumber - 1).ToString
currentQty = Integer.Parse(qtyList.Item(itemNumber - 1).ToString)
' CREATE COMMAND AND SET PARAMETERS
invCmd = New OleDbCommand
invCmd.CommandType = CommandType.Text
invCmd.CommandText = "SELECT invMain.PartNumber, invMain.Description1, " & _
"invMain.Description2, invMain.Type, invMain.Inventory" & _
" FROM invMain" & " WHERE (invMain.PartNumber='@comp')"
invCmd.Parameters.Add("@comp", OleDb.OleDbType.Char)
invCmd.Parameters("@comp").Value = currentItem
invCmd.Connection = invCon
' EXECUTE COMMAND
invRdr = invCmd.ExecuteReader
' IF DATA, READ INVENTORY
If invRdr.HasRows Then
invQty = Integer.Parse(invRdr(4).ToString)
Else
MessageBox.Show("No Rows")
End If
MessageBox.Show(currentItem & " " & invQty.ToString)
' COMPARE QUANTITIES
If invQty < currentQty * buildQty Then
itemsShort = itemsShort + 1
canBuild = invQty \ currentQty
If canBuild < totalCanBuild Then
totalCanBuild = canBuild
End If
End If
' CLOSE READER FOR NEXT ITEM
invRdr.Close()
Next itemNumber
' IF INVENTORY IS SHORT, NOTIFY USER, RETURN PROCEED = FALSE
If itemsShort > 0 Then
MessageBox.Show("Insufficient inventory exists for " & itemsShort & " item(s)" & _
"at the selected quantity. " & vbCrLf & "You can build " & totalCanBuild & _
" units with current inventory levels.")
proceed = False
Else
' INVENTORY IS SUFFICIENT, RETURN PROCEED = TRUE
proceed = True
End If
' CLOSE CONNECTION
invCon.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
proceed = False
End Try
End Sub
Any guidance you can provide is greatly appreciated. Also, would it be easier if I switched to ADODB instead of using ADOX?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|