Solved

return stored procedure output value in vb.net

Posted on 2009-05-06
1
800 Views
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.
0
Comment
Question by:v4seasons
[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
1 Comment
 
LVL 4

Accepted Solution

by:
cauos earned 250 total points
ID: 24312080
this code snippet below show how to create a stored procedure and call it from asp.net page
Sql Stored Procedure
Create PROCEDURE [dbo].[RS_TestGetUserName] 
 
@UserID int,
@username nvarchar(50) output
AS
begin
select @username = user_username from users where userid=@Userid
end
-------------------
VB.net 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
            con.Open()
 
            cmd.ExecuteNonQuery()
            Dim username As String = cmd.Parameters("@username").Value.ToString()
            con.Close()

Open in new window

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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