Solved

VB.NET and Stored Procedure Parameter

Posted on 2006-06-26
4
233 Views
Last Modified: 2008-02-26
It seems that no matter what I do, I keep getting the following error:
Prodedure 'CreateSession' expects parameter '@Result', which was not supplied - .NET SqlClient Data Provider
-------------------

Here is my code... Im sure I'm overlooking something... but I just can't find it.

-------------------

Dim pAppurl As New SqlParameter("@appurl", SqlDbType.VarChar, 250, ParameterDirection.Input)
            Dim pCurrurl As New SqlParameter("@currurl", SqlDbType.VarChar, 250, ParameterDirection.Input)
            Dim pUservalue As New SqlParameter("@uservalue", SqlDbType.VarChar, 50, ParameterDirection.Input)
            Dim pUserip As New SqlParameter("@Userip", SqlDbType.VarChar, 20, ParameterDirection.Input)
            Dim pTimeout As New SqlParameter("@timeout", SqlDbType.Int, 2, ParameterDirection.Input)
            Dim pGUID As New SqlParameter("@Result", SqlDbType.VarChar, 50)
            pGUID.Direction = ParameterDirection.ReturnValue

            Try
                If oConn.State <> ConnectionState.Open Then
                    oConn.Open()
                End If

                Dim oCmdSP As New SqlCommand
                oCmdSP.CommandType = CommandType.StoredProcedure
                oCmdSP.CommandText = "CreateSession"
                oCmdSP.Connection = oConn

                pAppurl.Value = strAppurl
                pCurrurl.Value = strCurrurl
                pUservalue.Value = strUservalue
                pUserip.Value = strUserip
                pGUID.Value = ""

                oCmdSP.Parameters.Add(pAppurl)
                oCmdSP.Parameters.Add(pCurrurl)
                oCmdSP.Parameters.Add(pUservalue)
                oCmdSP.Parameters.Add(pUserip)
                oCmdSP.Parameters.Add(pGUID)

                If intTimeout <> 0 Then
                    pTimeout.Value = intTimeout
                    oCmdSP.Parameters.Add(pTimeout)
                End If

                oCmdSP.ExecuteNonQuery()
0
Comment
Question by:Michael Krumpe
4 Comments
 
LVL 12

Expert Comment

by:vb_jonas
ID: 16987193
Looks fine, how does the sql-procedure look? And why do you set the pGUID.Value=""?
0
 
LVL 4

Author Comment

by:Michael Krumpe
ID: 16987251
The stored proc is declared as follows

ALTER PROCEDURE [dbo].[CreateSession]
      @appurl varchar(250),
      @currurl varchar(250),
      @uservalue varchar(50),
      @userip varchar(20),
      @timeout int = 0,
      @Result varchar(50) OUTPUT
AS


--------------

I just stuck that pGUID.Value = "" because I kept getting this same error and thought maybe I needed to push "something" to it.

Any thoughts?
0
 
LVL 4

Accepted Solution

by:
sr101880 earned 500 total points
ID: 16987631
You need to change:

pGUID.Direction = ParameterDirection.ReturnValue


to

pGUID.Direction = ParameterDirection.Output

Let me know if you have any questions.
0
 
LVL 2

Expert Comment

by:Bill_PSC
ID: 16987802
Try this

oCmdSP.SelectCommand.Parameters(pAppurl).Value = pAppurl
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

21 Experts available now in Live!

Get 1:1 Help Now