Call user defined procedures in ASP.NET
i have create a procedure that takes number from a table add them and gives he average of those numbers in sql. now i want to call that procedure in asp.net. can somebody tells me how to call that procedure.?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Javeed M ShaikhPosted Oct 11, 2011, 10:41 AM
You have call the stored procedure from the Code behind using SQL Objects, following is the code snippet ( I am assuming that you have the stored procedure already written):
SqlConnection MyConn = new SqlConnection("ConnectionString");
SqlCommand MyCMD = new SqlCommand("ProcedureName", MyConn);
MyCMD.CommandType = CommandType.StoredProcedure;
SqlParameter RetVal = MyCMD.Parameters.Add("RetVal", SqlDbType.Int);
RetVal.Direction = ParameterDirection.ReturnValue;
MyConn.Open();
MyCMD.ExecuteNonQuery();
Console.WriteLine("Return Value: " + RetVal.Value);
MyConn.Close();
Please do not forget to mark "Accepted Answer".
Prabhu RajaPosted Oct 12, 2011, 2:13 AM
Also try this . You may get more About Working with SP in ASp.Net. Click Here