Solved

Argument not specified for parameter

Posted on 2009-04-14
18
285 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now