Solved

Argument not specified for parameter

Posted on 2009-04-14
18
287 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
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 22

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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get number of Files in Directory and Sub Directories 2 48
JSON  parse help 7 40
VS 2017 18 36
VB.net Use code to open two DateTimePickers at the same time 7 34
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 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