Saturday, 27 April 2013

Give an example that shows how to execute a stored procedure in ADO.NET? | ASP.Net interview questions

using (SqlConnectionConnectionObject = new SqlConnection())
{
//Specify the name of the stored procedure to execute and the Connection Object to use
SqlCommandCommandObject = new SqlCommand("StoredProcedureName", ConnectionObject);
//Specify the SQL Command type is a stored procedure
CommandObject.CommandType = CommandType.StoredProcedure;
//Open the connection
ConnectionObject.Open();
//Execute the Stored Procedure
intRecordsAffected = CommandObject.ExecuteNonQuery();
}

No comments: