Seven price
asked on
Argument not specified for parameter
Hey guys, I am trying to have a verification. If the user enters a quantity that is higher than teh one
specified in the database and error comes up else process.
but I keep getting and error that i really do not understand. ((Argument not specified for parameter))
specified in the database and error comes up else process.
but I keep getting and error that i really do not understand. ((Argument not specified for parameter))
Private Function VerifyUnicValidatingUpdate(ByVal Quantityava As Integer) As Boolean
Dim productId As Integer
Dim conn33 As New SqlConnection("ConnString")
Dim cmd33 As New SqlCommand("checkforQuantityava", conn33)
cmd33.CommandType = CommandType.StoredProcedure
Dim sqlDR As SqlDataReader
Dim paramQuantity As New SqlParameter("@Quantityava", Quantityava)
Dim paramProdID As New SqlParameter("@productId", Productid)
cmd33.Parameters.Add(paramQuantity)
cmd33.Parameters.Add(paramProdID)
conn33.Open()
sqlDR = cmd33.ExecuteReader
VerifyUnicValidatingUpdate = True
While sqlDR.Read
If Quantityava <> sqlDR("QuantityAva") Then
VerifyUnicValidatingUpdate = True
Exit While
Else
VerifyUnicValidatingUpdate = False
End If
End While
If (Not sqlDR Is Nothing) Then
If Not (sqlDR.IsClosed) Then
sqlDR.Close()
End If
End If
sqlDR = Nothing
If (Not conn33 Is Nothing) Then
If conn33.State <> ConnectionState.Closed Then conn33.Close()
conn33.Dispose()
End If
If Not cmd33 Is Nothing Then cmd33.Dispose()
Return VerifyUnicValidatingUpdate()
End Function
#End Region
storedprocedure:
(@Quantityava as varchar(150),
@productId as int)
AS
BEGIN
SELECT Quantityava FROM Product WHERE Quantityava = @Quantityava And ProductId = @ProductId
End
DONE:
Can you show the actual exception message? Nothing's jumping out at me.
Is it messing something up on the types?
I notice you're passing Quantityava to the VB function as an integer, but the stored proc is expecting a varchar...
I notice you're passing Quantityava to the VB function as an integer, but the stored proc is expecting a varchar...
ASKER
Yes I know but I passed it as a string also but I still get the message.
Argument not specified for parameter Private Function VerifyUnicValidatingUpdate (ByVal Quantityava As Integer) As Boolean
Argument not specified for parameter Private Function VerifyUnicValidatingUpdate
Hi!
Replace
Return VerifyUnicValidatingUpdate ()
with
Return VerifyUnicValidatingUpdate
Replace
Return VerifyUnicValidatingUpdate
with
Return VerifyUnicValidatingUpdate
Ah, it was a compile error rather than a run-time error. Just some advice for the future, including in the question when the error occurs, and at what point it occurs, along with the actual message will help a great deal.
You should also try staying away for setting the return value using the variable with the function name, use return instead.
You should also try staying away for setting the return value using the variable with the function name, use return instead.
' VB6 way
private function Foo(i as integer) as boolean
Foo = (i > 0)
end function
' .Net way, and far more readable
private function Foo(i as integer) as boolean
return (i > 0)
end function
Private Function VerifyUnicValidatingUpdate(ByVal Quantityava As Integer) As Boolean
Dim productId As Integer
Dim conn33 As New SqlConnection("ConnString")
Dim cmd33 As New SqlCommand("checkforQuantityava", conn33)
cmd33.CommandType = CommandType.StoredProcedure
Dim sqlDR As SqlDataReader
Dim paramQuantity As New SqlParameter("@Quantityava", Quantityava)
Dim paramProdID As New SqlParameter("@productId", Productid)
cmd33.Parameters.Add(paramQuantity)
cmd33.Parameters.Add(paramProdID)
conn33.Open()
sqlDR = cmd33.ExecuteReader
Try
While sqlDR.Read
If Quantityava <> sqlDR("QuantityAva") Then
return True
End If
End While
return False
Finally
' The code in finally always runs, even though you've called return already
If (Not sqlDR Is Nothing) Then
If Not (sqlDR.IsClosed) Then
sqlDR.Close()
End If
End If
sqlDR = Nothing
If (Not conn33 Is Nothing) Then
If conn33.State <> ConnectionState.Closed Then conn33.Close()
conn33.Dispose()
End If
If Not cmd33 Is Nothing Then cmd33.Dispose()
End Try
End Function
ASKER
What about on the return I get the same error when i try to use this in my button function
If VerifyUnicValidatingUpdate() = True Then
UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@ProductID", q))
UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@Quantity", h))
ASKER
here is the error.
\shoppingCart.ascx.vb(383) : Argument not specified for parameter 'Quantityava' of 'Private Function VerifyUnicValidatingUpdate (Quantitya va As Integer) As Boolean'.
\shoppingCart.ascx.vb(383)
Exactly as the error tells you. You haven't passed the Quantityava parameter to VerifyUnicValidatingUpdate
dim Quantityava as Interger = 123456
If VerifyUnicValidatingUpdate(Quantityava) = True Then
UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@ProductID", q))
UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@Quantity", h))
ASKER
Ok my friend, But now I get another error Could not find stored procedure 'checkforQuantityava' how is that possible. Again thanks
ASKER
ignore the last give me one second
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok when i tried my way i get a return but it always comes out to false.
When i tried your way I get no error no reponse to anything.
While sqlDR33.Read
If Quantityava < sqlDR33("QuantityAva") Then
Return False
End If
End While
Return True
When i tried your way I get no error no reponse to anything.
While sqlDR33.Read
If Quantityava < sqlDR33("QuantityAva") Then
Return False
End If
End While
Return True
'While sqlDR33.Read
' If Quantityava < sqlDR33("QuantityAva") Then
' VerifyUnicValidatingUpdate = True
' Exit While
' Else
' VerifyUnicValidatingUpdate = False
' End If
'End While
' Response.Write(Quantityava)
You've got true & false mixed up
ASKER
Ok that should not matter in this case. when a user lets in the database the quantity stops at 200. if a user adds 150 in the quantityava textbox or 199 everything should be false but if a user goes over for example 201 or 300 then a response should be true and an error should come up.
ASKER
If Quantityava < sqlDR33("QuantityAva")
Ok no matter what is comes back to False, any other ideas my friend.
Ok no matter what is comes back to False, any other ideas my friend.
Sounds like you're comparing 2 different datatypes. What type of data is Quantityava in the Product table?
How about using this to compare. Otherwise add a breakpoint, and check what values is being returned.
How about using this to compare. Otherwise add a breakpoint, and check what values is being returned.
If Quantityava < CInt(sqlDR33("QuantityAva"))
ASKER
My debugger does not work on this server that sucks. But what if I am looking the wrong place. Quantityava is looking the in the main table. But Quantity is the text box not sql(Quantityava)
ASKER
I am sorry I have been comparing with Quantityava in reality I need to compare Quantityava with Me.mybox.Text do I have to use the same scenario for this validation