I was creating the same method over and over again to execute different stored procedures. Now I have created one general method which you can use for all stored procedures (with no result set). Off course it can be extended with, for example, the return of a datatable:
public void ExecuteStoredProcedure(string name, string[] parameters, object[] values)
{
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
connection.Open();
try
{
SqlCommand command = new SqlCommand(name, connection);
command.CommandType = CommandType.StoredProcedure;
for (int i = 0; i < parameters.Length; i++)
{
command.Parameters.Add(new SqlParameter(parameters[i], values[i]));
}
command.ExecuteNonQuery();
}
catch (Exception ex)
{
}
finally
{
connection.Close();
}
}
}
053f10f9-6438-4090-ba8b-0e0857f7e847|0|.0