Solved

VB.NET and Stored Procedure Parameter

Posted on 2006-06-26
4
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
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…

726 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