예제 #1
0
        public static Citys getcity(int city_id)
        {
            Citys            c               = new Citys();
            NpgsqlConnection connection      = accountDB.GetConnection();
            string           selectStatement =
                "SELECT *" +
                "FROM citys " +
                "WHERE city_id = @city_id";
            NpgsqlCommand selectCommand = new NpgsqlCommand(selectStatement, connection);

            selectCommand.Parameters.AddWithValue("@city_id", city_id);
            try
            {
                connection.Open();
                NpgsqlDataReader reader = selectCommand.ExecuteReader();
                if (reader.Read())
                {
                    c.mcity_id  = (int)reader["city_id"];
                    c.mname     = reader["city"].ToString();
                    c.mzip_code = reader["zip_code"].ToString();
                }
                else
                {
                    c = null;
                }
                reader.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
            return(c);
        }