public int ExecuteNonQuery(string storedProcedure, params SqlParameter[] parameters)
{
using (SqlConnection connection = new SqlConnection(ConnectionString))
using (SqlCommand command = new SqlCommand(storedProcedure, connection))
{
if(parameters != null)
{
command.Parameters.AddRange(parameters);
}
command.CommandType = CommandType.StoredProcedure;
try
{
connection.Open();
return command.ExecuteNonQuery();
}
finally
{
connection.Close();
}
}
}