topher-b
8/27/2015 - 3:52 PM

Propper Sql Requests

Propper Sql Requests

using (SqlConnection connection = new SqlConnection("ConnectionString"))
{
  connection.Open();
  using (SqlCommand command = new SqlCommand("SprocName", connection))
  {
    command.CommandType = CommandType.StoredProcedure;
    #region Parameters
    command.Parameters.AddWithValue("@variable", value);
    #endregion
    //Execute as NonQuery
    command.ExecuteNonQuery();
    // OR as Query
    using (SqlDataReader reader = command.ExecuteReader())
    {
      while (reader.Read())
      {
      }
    }
    //Execute end
  }
  connection.Close();
}