Monday, October 5, 2009

Executing a Stored Procedure

When we consider about the SqlCommand type it has basically Stored Procedure, Table Direct and Text. Therefore we can easily provide the SqlCommand type as a Stored Procedure. And can be used to execute it. To success that basically it should require two tasks.

• SqlCommand object should know which Stored Procedure to Execute.
• SqlCommand object that it is executing a stored procedure

These two steps are shown below.

// 1. create a command object identifying
// the stored procedure
SqlCommand cmd = new SqlCommand(
"Name of Stored Procedure to Execute", conn);

// 2. set the command object so it knows
// to execute a stored procedure
cmd.CommandType = CommandType.StoredProcedure;

According to that SqlCommand object have two parameter first one is the Name of the Stored Procedure which you are going to execute. And next parameter is the data base connection.

As second step it shows that it selected command type property as a Stored Procedure it is very important. Otherwise it will not be work properly according to our purpose.


Your Comments are highly appreciated; it will be improving my knowledge also.

0 comments:

About This Blog

  © Blogger templates 'Neuronic' by Ourblogtemplates.com 2008

Back to TOP