?
Solved

Can't get my stored proc OUTPUT parameters to come back in my ASP.NET application

Posted on 2007-03-30
7
Medium Priority
?
245 Views
Last Modified: 2013-11-26
I'm unable to get my OUTPUT parameters to come back properly. I have ran my stored proc with the values I'm using in my app in query analyzer and it works fine. I'm going crazy.

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

Dim myConnection As New SqlConnection("server=(local);database=uw_data;uid=jrmcintosh;pwd=ncr3170")
            myConnection.Open()

            Dim myCommand As New SqlCommand("usp_sel_getuser", myConnection)
            myCommand.CommandType = CommandType.StoredProcedure
            Dim uwuser As New SqlParameter("@user", SqlDbType.VarChar, 1)
            uwuser.Value = txtEmail.Text
            myCommand.Parameters.Add(uwuser)
            Dim pass As New SqlParameter("@password", SqlDbType.VarChar, 1)
            pass.Value = txtPassword.Text
            myCommand.Parameters.Add(pass)
            Dim success As New SqlParameter("@success", SqlDbType.Int, 4)
            success.Direction = ParameterDirection.Output
            myCommand.Parameters.Add(success)
            Dim userid As New SqlParameter("@userid", SqlDbType.VarChar, 1)
            userid.Direction = ParameterDirection.Output
            myCommand.Parameters.Add(userid)
            myCommand.ExecuteNonQuery()

            Dim count As Int16 = success.Value
            Session("userid") = userid.Value

            lblcount.Text = count

            myConnection.Close()
0
Comment
Question by:jrmcintosh
[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
  • 3
7 Comments
 
LVL 11

Expert Comment

by:dready
ID: 18825401
Did you declarre the parameters as output in the stored procedure usp_sel_getuser ????
0
 

Author Comment

by:jrmcintosh
ID: 18825462
yes

CREATE PROCEDURE dbo.usp_sel_getuser

@user varchar(100),
@password varchar(100),
@success int OUTPUT,
@userid varchar(100) OUTPUT

AS

SELECT * from uw_users where userid = @user  AND pass = @password

SET @userid = (SELECT userid from uw_users where userid = @user AND pass = @password)

SET @success = (select COUNT(*) from uw_users where userid = @user AND pass = @password)

GO
0
 

Author Comment

by:jrmcintosh
ID: 18825467
This is my first time using this method of calling a stored procedure. I have been using the enterprise library method for the past year so this is new to me...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:dready
ID: 18825477
So, your stp should look something like

CREATE PROCEDURE usp_sel_getuser
@user varchar(50),   -- This is a input parameter.
@password varchar(50),
@success int OUTPUT,
@userid varchar OUTPUT
AS  
-- here you do something.

Also, I am  not sure wetheryou set the length of your params correctly in the VB code
0
 

Author Comment

by:jrmcintosh
ID: 18825498
we must've put messages at the same time, I have my stored proc above. I also do not know if I'm setting my lengths correctly.
0
 
LVL 11

Accepted Solution

by:
dready earned 1000 total points
ID: 18825573
I think you set the size wrong, if im not mistaken, the third param is the lengh, so try this: (I chanced the 3rd param from 1 to 100 in 3 places.)

     myConnection.Open()

            Dim myCommand As New SqlCommand("usp_sel_getuser", myConnection)
            myCommand.CommandType = CommandType.StoredProcedure
            Dim uwuser As New SqlParameter("@user", SqlDbType.VarChar, 100)
            uwuser.Value = txtEmail.Text
            myCommand.Parameters.Add(uwuser)
            Dim pass As New SqlParameter("@password", SqlDbType.VarChar, 100)
            pass.Value = txtPassword.Text
            myCommand.Parameters.Add(pass)
            Dim success As New SqlParameter("@success", SqlDbType.Int, 4)
            success.Direction = ParameterDirection.Output
            myCommand.Parameters.Add(success)
            Dim userid As New SqlParameter("@userid", SqlDbType.VarChar, 100)
            userid.Direction = ParameterDirection.Output
            myCommand.Parameters.Add(userid)
            myCommand.ExecuteNonQuery()

            Dim count As Int16 = success.Value
            Session("userid") = userid.Value

            lblcount.Text = count

            myConnection.Close()
0
 

Author Comment

by:jrmcintosh
ID: 18825780
That was it, thanks.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

765 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