Exemplo n.º 1
0
        /// <summary>
        /// Delete an entry from the PostalCode table
        /// </summary>
        public static bool Delete(int postalCode)
        {
            Int32         rowsAffected = 0;
            SqlConnection cn           = GetConnection();
            ZipCode       zipCode      = Get(cn, postalCode);

            if (zipCode != null)
            {
                using (SqlCommand sqlCmd = cn.CreateCommand())
                {
                    sqlCmd.CommandText = "DELETE FROM ZipCode WHERE ZipCodePostalCode=" + postalCode;
                    rowsAffected       = sqlCmd.ExecuteNonQuery();
                }
            }
            FinishedWithConnection(cn);
            return(rowsAffected != 0);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a new entry to the PostalCode table
        /// </summary>
        public static ZipCode Add(int postalCode, int cityId)
        {
            ZipCode result = null;

            SqlConnection cn = GetConnection();

            using (SqlCommand sqlCmd = cn.CreateCommand())
            {
                sqlCmd.CommandText = "INSERT INTO ZipCode (ZipCodePostalCode, ZipCodeZipCodeCityId) VALUES (@ZipCodePostalCode, @ZipCodeZipCodeCityId)";
                BuildSqlParameter(sqlCmd, "@ZipCodePostalCode", SqlDbType.Int, postalCode);
                BuildSqlParameter(sqlCmd, "@ZipCodeZipCodeCityId", SqlDbType.Int, cityId);
                if (sqlCmd.ExecuteNonQuery() > 0)
                {
                    result = new ZipCode(postalCode, cityId);
                }
            }
            FinishedWithConnection(cn);

            return(result);
        }
Exemplo n.º 3
0
 public bool Update()
 {
     return(ZipCode.Update(this));
 }