how to get sql variable Value in my stored procedure , from C# application??
hi all , i have create stored procedure , this procedure contain variable will hold important value , i want to get variable value into C# , how?? like this
DECLARE @NUMBER INT
SET @NUMBER = 1
Master BillaPosted Aug 16, 2009, 10:17 PM
You can select @NUmber end of the Stored procedure, if your Sp returning only one value, you can write code like this way
Private object GetData()
{
using (SqlConnection con = new SqlConnection("Con"))
{
if (con.State != System.Data.ConnectionState.Open)
{
con.Open();
}
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "SPName";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
object data = cmd.ExecuteScalar();
if (data != null)
{
return data;
}
}
}
}
Note:If you have more than one column we need use the SqlDataReader to access.thank you
abas shahenPosted Aug 16, 2009, 5:34 PM
DanPosted Aug 16, 2009, 5:30 PM
Assuming you're using a SQLCommand object called com you add parameters like this:
com.Parameters.AddWithValue("@MYPARAM", "Test Value");