Solved

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

Posted on 2007-03-30
7
241 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
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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 250 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

749 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