How to

execute stored procedure with parameters

Published: 14. December 2008 | Updated: 14. December 2008
License: Microsoft Public License (MS-PL)
Categories: Databases
Tags: C# SQL
Was this snippet helpful for you? YESYES / NONO

Import namespace

using System.Data.SqlClient;

Code

// create connection
SqlConnection sqlConnection = new SqlConnection("...");
sqlConnection.Open();

// create command
SqlCommand command = new SqlCommand("stored_procedure_name", connection);
command.CommandType = CommandType.StoredProcedure;

// add parameter
command.Parameters.AddWithValue("@id", id);

// execute
int affectedRows = command.ExecuteNonQuery();
Send us feedback about this snippet »



Related Snippets: