Solved

VB.NET and Stored Procedure Parameter

Posted on 2006-06-26
4
231 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

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

20 Experts available now in Live!

Get 1:1 Help Now