Link to home
Start Free TrialLog in
Avatar of Michael Krumpe
Michael KrumpeFlag for United States of America

asked on

VB.NET and Stored Procedure Parameter

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()
Avatar of vb_jonas
vb_jonas
Flag of Sweden image

Looks fine, how does the sql-procedure look? And why do you set the pGUID.Value=""?
Avatar of Michael Krumpe

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of sr101880
sr101880

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill_PSC
Bill_PSC

Try this

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