Solved

Argument not specified for parameter

Posted on 2009-04-14
18
289 Views
Last Modified: 2012-05-06
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))

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:

Open in new window

0
Comment
Question by:sevensnake77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
18 Comments
 
LVL 15

Expert Comment

by:oobayly
ID: 24143195
Can you show the actual exception message? Nothing's jumping out at me.
0
 
LVL 23

Expert Comment

by:Snarf0001
ID: 24143443
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...
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24144118
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

0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 13

Expert Comment

by:drypz
ID: 24145019
Hi!
Replace

     Return VerifyUnicValidatingUpdate()

with

     Return VerifyUnicValidatingUpdate
0
 
LVL 15

Expert Comment

by:oobayly
ID: 24146076
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.
' 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

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24147990
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))

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24148021
here is the error.
\shoppingCart.ascx.vb(383): Argument not specified for parameter 'Quantityava' of 'Private Function VerifyUnicValidatingUpdate(Quantityava As Integer) As Boolean'.


0
 
LVL 15

Expert Comment

by:oobayly
ID: 24148373
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))

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24148463
Ok my friend, But now I get another error Could not find stored procedure 'checkforQuantityava' how is that possible.  Again thanks
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24148537
ignore the last give me one second
0
 
LVL 15

Accepted Solution

by:
oobayly earned 500 total points
ID: 24148632
Double check the stored procedure's name on the server. Sql Server isn't case sensitive, but you may have a space in your VB code.

You could also name it explicitly:
Dim cmd33 As New SqlCommand("[database].[dbo].[checkforQuantityava]", conn33)

database is the name of the your database
dbo is the prefix
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24148889
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


 'While sqlDR33.Read
            '    If Quantityava < sqlDR33("QuantityAva") Then
            '        VerifyUnicValidatingUpdate = True
            '        Exit While
            '    Else
 
            '        VerifyUnicValidatingUpdate = False
            '    End If
            'End While
            ' Response.Write(Quantityava)

Open in new window

0
 
LVL 15

Expert Comment

by:oobayly
ID: 24148991
You've got true & false mixed up
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24149085
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.
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24149362
If Quantityava < sqlDR33("QuantityAva")

Ok no matter what is comes back to False, any other ideas my friend.
0
 
LVL 15

Expert Comment

by:oobayly
ID: 24149488
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.
If Quantityava < CInt(sqlDR33("QuantityAva"))

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24150022
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)
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 24150108
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
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question