コード例 #1
0
        public List <Country> List()
        {
            string strStoredProc = ProcedureHelper.GetProc(EnumProcedures.GetCountries);

            SqlConnection con = GetConnection();

            con.Open();
            SqlCommand     cmd       = new SqlCommand(strStoredProc, con);
            SqlDataReader  reader    = cmd.ExecuteReader();
            List <Country> countries = new List <Country>();

            while (reader.Read())
            {
                if (!reader.IsDBNull(reader.GetOrdinal("Name")) && !reader.IsDBNull(reader.GetOrdinal("ID")))
                {
                    countries.Add(new Country()
                    {
                        Name = reader["Name"].ToString(), ID = reader["ID"].ToString()
                    });
                }
            }
            con.Close();

            return(countries);
        }
コード例 #2
0
        public void Create(string countryName)
        {
            string strStoredProc = ProcedureHelper.GetProc(EnumProcedures.CreateCountry);

            SqlConnection con = GetConnection();

            SqlCommand cmd = new SqlCommand(strStoredProc, con);

            cmd.Parameters.AddWithValue("@cName", countryName);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }