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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Priya LingeRank #785 · 2.9K reputationPosted Oct 31, 2011, 8:29 PM EDT
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.
Suthish NairRank #92 · 22.8K reputationPosted Nov 1, 2011, 1:42 AM EDT
refer this article: DataGridView - Insert, Update, Delete and Retrieve records using stored procedure
Deepak DwijRank #348 · 7.2K reputationPosted Nov 14, 2011, 1:59 PM EST