I typed this off the top of my head, so it might need some minor tweaking, but this is a more correct way to do this.
public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
int result = 0;
if (string.IsNullOrEmpty(connectionString)
{
throw new ArgumentNullException("connectionString");
}
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using SqlCommand cmd = new SqlCommand(commandText, conn))
{
cmd.CommandType = commandType;
cmd.Parameters.AddRange(commandParameters);
result = cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
}
return result;
}