示例#1
0
        private static Product selectProduct(int id)
        {
            Product product = new Product();

            using (MySqlCommand command = con.CreateCommand())
            {
                command.CommandText = "SELECT *  FROM pz.goods where goods.id = @Id";
                command.Parameters.Add(new MySqlParameter("@Id", id));
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        product.setId(int.Parse(reader["id"].ToString()));
                        product.setName(reader["name"].ToString());
                        product.setDetails(reader["details"].ToString());
                        product.setPotoUrl(reader["photo_url"].ToString());
                        product.setPrice(decimal.Parse(reader["price"].ToString()));
                        product.setNumber(int.Parse(reader["number"].ToString()));
                    }
                }
            }
            return(product);
        }
示例#2
0
        public static List <Product> getProducts()
        {
            List <Product> products = new List <Product>();

            using (MySqlCommand command = con.CreateCommand())
            {
                command.CommandText = "SELECT *  FROM pz.goods";
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var product = new Product();
                        product.setId(int.Parse(reader["id"].ToString()));
                        product.setName(reader["name"].ToString());
                        product.setDetails(reader["details"].ToString());
                        product.setPotoUrl(reader["photo_url"].ToString());
                        product.setPrice(decimal.Parse(reader["price"].ToString()));
                        product.setNumber(int.Parse(reader["number"].ToString()));
                        products.Add(product);
                    }
                }
            }
            return(products);
        }