Introduction:
In this article I will explain how to get output parameters returns by stored procedure in asp.net.
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.
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. |
|||
|
|||
3 comments :
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
message = (string) cmd.Parameters["@Output "].Value;
how to bring the message in view
please answer my
questions
Note: Only a member of this blog may post a comment.