Calling Stored Procedure using ADO.Net
I want to call a stored procedure through the use of ADO.Net. How can I do that
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.
Deepak DwijPosted Nov 14, 2011, 6:59 PM
Suthish NairPosted Nov 1, 2011, 5:42 AM
refer this article: DataGridView - Insert, Update, Delete and Retrieve records using stored procedure
Priya LingePosted Nov 1, 2011, 12:29 AM
1.Stored Procedure :
CREATE PROCEDURE RegionUpdate (@RegionID INTEGER,
@RegionDescription NCHAR(50)) AS
SET NOCOUNT OFF
UPDATE Region
SET RegionDescription = @RegionDescription
2.Initially create a object of SqlConnection class which is available
in System.Data.SqlClient namespace
SqlConnection con = new SqlConnection("Data Source= ; initial catalog= Northwind ; User Id= ; Password= '");
con.open();
3.Create a SqlCommand object with the parameters as the name of the stored procedure that is to be executed and the connection object con to which
the command is to be sent for execution.
SqlCommand command = new SqlCommand("RegionUpdate",con);
4.Change the command objects CommandType property to stored procedure.
command.CommandType = CommandType.StoredProcedure;
5.Add the parameters to the command object using the Parameters collection and the SqlParameter class.
command.Parameters.Add(new SqlParameter("@RegionID",SqlDbType.Int,0,"RegionID"));
command.Parameters.Add(new SqlParameter("@RegionDescription",SqlDbType.NChar,50,"RegionDescription"));
Please check below link for more information.
http://www.a2zdotnet.com/View.aspx?Id=20
Hope this will help you.
Thanks.