Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

return stored procedure output value in vb.net

Posted on 2009-05-06
1
Medium Priority
?
806 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

604 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