return stored procedure output value in

Posted on 2009-05-06
Last Modified: 2013-11-26
I have seen the examples on returning parameters in stored  procedures that use the OUTPUT value.  I am unclear on the syntax however for returning the actual varchar value that is returned by the stored procedure.  It seems the examples return a value of 0 or 1.  How can I call the stored procedure with it's three paramaters and return the varchar value that is returned when the stored procedure is ran into a variable?  I thought using the executescalar method would accomplish this but it does not seem to be working.  Does anyone have any sample code I can look at?  Please advise.
Question by:v4seasons
1 Comment

Accepted Solution

cauos earned 250 total points
ID: 24312080
this code snippet below show how to create a stored procedure and call it from page
Sql Stored Procedure

Create PROCEDURE [dbo].[RS_TestGetUserName] 

@UserID int,

@username nvarchar(50) output



select @username = user_username from users where userid=@Userid


------------------- code calling the stored procedure 

Dim constr As String = ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString

            Dim con As New SqlConnection(constr)

            Dim cmd As New SqlCommand("RS_TestGetUserName", con)

            cmd.CommandType = Data.CommandType.StoredProcedure

            cmd.Parameters.AddWithValue("@UserID", 38107)

            cmd.Parameters.Add("@username", Data.SqlDbType.NVarChar, 50)

            cmd.Parameters("@username").Direction = Data.ParameterDirection.Output



            Dim username As String = cmd.Parameters("@username").Value.ToString()


Open in new window


Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
crm development 2 37
Default parameter problem in C# 3 27
Library to convert HTML to PDF. 8 46
Spacing between controls 4 17
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

746 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

13 Experts available now in Live!

Get 1:1 Help Now