Good morning!
I have been staring at this code for two days now and I absolutely cannot figure out why it throws an error at bomRdr = bomCmd.ExecuteReader. The error thrown is: No value given for one or more required parameters. However, I have tried inserting a messagebox before the ExecuteReader to show all necessary values at runtime and everything looks good. Furthermore, most of this code was copy and pasted from another of my subroutines that functions perfectly. Please help!
Code:Sub CheckForSufficientInventory(ByRef proceed As Boolean, ByRef bomList As StringCollection, _ ByRef qtyList As StringCollection) ' CHECK STRINGCOLLECTION ARRAY AGAINST INVENTORY ' PROCEED IF SUFFICIENT INVENTORY OR ' NOTIFY USER OF DEFICIENCIES ' GIVE OPTION TO OVERRIDE Dim canBuild As Integer Dim itemsShort As Integer = 0 Dim itemNumber As Integer Dim itemToFind As String Dim buildQty As Integer = Integer.Parse(Me.uiQtyTextBox.Text) Dim totalCanBuild As Integer = buildQty Dim bomConString As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data " & _ "Source=….mdb;" & _ "Jet OLEDB:Database Password=******;" ' CREATE CONNECTION AND OPEN bomCon = New OleDbConnection(bomConString) bomCon.Open() Try ' CHECK INVENTORY For itemNumber = 1 To bomList.Count ' CREATE COMMAND AND SET PARAMETERS itemToFind = Convert.ToString(bomList.Item(itemNumber - 1)) bomCmd = New OleDbCommand("SELECT Inventory.invMain FROM invMain WHERE (PartName = @comp)", bomCon) bomCmd.Parameters.Add("@comp", OleDb.OleDbType.Char) bomCmd.Parameters("@comp").Value = itemToFind ' EXECUTE COMMAND bomRdr = bomCmd.ExecuteReader While bomRdr.Read Dim invQty As Integer = Integer.Parse(Convert.ToString(bomRdr(0))) ' COMPARE QUANTITIES If invQty < Integer.Parse(qtyList.Item(itemNumber - 1)) * buildQty Then itemsShort = itemsShort + 1 canBuild = invQty \ Integer.Parse(qtyList.Item(itemNumber - 1)) If canBuild < totalCanBuild Then totalCanBuild = canBuild End If End If End While ' CLOSE READER FOR NEXT ITEM bomRdr.Close() Next itemNumber If itemsShort > 0 Then MessageBox.Show("Insufficient inventory exists for " & itemsShort & " item(s)" & vbCrLf & _ "at the selected quantity. You can build " & totalCanBuild & vbCrLf & _ "units with current inventory levels.") proceed = False Else proceed = True End If bomCon.Close() Catch ex As Exception MessageBox.Show(ex.Message) proceed = False End Try End Sub




Reply With Quote