Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Get output parameter from stored procedure in asp.net

Jul 9, 2012
Introduction

In this article I will explain how to get output parameters returns by stored procedure in asp.net.

Description:

In previous posts I explained many articles relating asp.net,
gridview, JQuery, SQL Server etc. Now I will explain how to get output parameters return by stored procedure in asp.net. First we will see how to write a stored procedure to return output parameters for that check this post write stored procedure to return output parameters in SQL Server. Once stored procedure designed in database write the following code in code behind to get output parameters returns by stored procedure in asp.net.

Generally if we want to get output parameters return by stored procedure in asp.net we will write like this

C# Code

string message = String.Empty;
SqlCommand cmd = new SqlCommand("sp_userinformation", con);
cmd.Parameters.Add("@Output", SqlDbType.Char, 500);
cmd.Parameters["@Output "].Direction = ParameterDirection.Output;
message = (string) cmd.Parameters["@Output "].Value;
Here sp_userinformation is a stored procedure and @Output is parameter which is used to get the output parameter return by stored procedure.

VB.NET Code

Dim message As String = [String].Empty
Dim cmd As New SqlCommand("sp_userinformation", con)
cmd.Parameters.Add("@Output", SqlDbType.[Char], 500)
cmd.Parameters("@Output ").Direction = ParameterDirection.Output
message = DirectCast(cmd.Parameters("@Output ").Value, String)
If you want to know how to write this code in application check this post

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

3 comments :

Chandru said...

Ther Article was nice. But i have found one error while exeucting the Sp in my front end is mentioned here weather i need to execute the command right but in u r post u have not done that so i confused

Anonymous said...

message = (string) cmd.Parameters["@Output "].Value;
how to bring the message in view

Anonymous said...

please answer my
questions

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.