コード例 #1
0
        static public BeautyProducts findById(int ProductId)
        {
            DB.connection.Open();

            string query = $"SELECT * FROM  dbo.BeautyProducts WHERE productId = '{ProductId}'";

            SqlCommand cmd = new SqlCommand(query, DB.connection);

            SqlDataReader reader = cmd.ExecuteReader();

            BeautyProducts temp = new BeautyProducts();

            if (reader.Read())
            {
                //Console.WriteLine(String.Format("{0}", reader[0]));
                temp.ProductId   = (int)reader[0];
                temp.ProductName = (string)reader[1];
                // continue doing it for all parameters ...

                return(temp);
            }

            DB.connection.Close();

            return(null);
        }
コード例 #2
0
        static public List <BeautyProducts> findAll(int ProductId)
        {
            DB.connection.Open();

            string query = $"SELECT * FROM  dbo.BeautyProducts";

            SqlCommand cmd = new SqlCommand(query, DB.connection);

            SqlDataReader reader = cmd.ExecuteReader();

            List <BeautyProducts> listOfProducts = new List <BeautyProducts>();

            while (reader.Read())
            {
                BeautyProducts temp = new BeautyProducts();
                //Console.WriteLine(String.Format("{0}", reader[0]));
                temp.ProductId   = (int)reader[0];
                temp.ProductName = (string)reader[1];
                // continue doing it for all parameters ...

                listOfProducts.Add(temp);
            }

            DB.connection.Close();

            return(listOfProducts);
        }