示例#1
0
        public Order Get(int id)
        {
            using (SqlConnection connection = conn.OpenConnection())
            {
                using (SqlCommand cmd = connection.CreateCommand())
                {
                    cmd.CommandText = "SELECT * FROM OrderDB WHERE Id = @id";
                    cmd.Parameters.AddWithValue("id", id);
                    SqlDataReader reader = cmd.ExecuteReader();

                    //Finding and fetching the result, by also fetching the customer
                    bool       isRead     = reader.Read();
                    DBCustomer dBCustomer = new DBCustomer();
                    Customer   c          = dBCustomer.Get(reader.GetInt32(2));
                    return(new Order(reader.GetInt32(0), c));
                }
                //connection.Close();
            }
        }
示例#2
0
        public List <Order> GetAll()
        {
            List <Order> OrderList = new List <Order>();

            using (SqlConnection connection = conn.OpenConnection())
            {
                using (SqlCommand cmd = connection.CreateCommand())
                {
                    cmd.CommandText = "SELECT * FROM OrderDB";
                    SqlDataReader reader = cmd.ExecuteReader();


                    while (reader.Read())
                    {
                        DBCustomer dBCustomer = new DBCustomer();
                        Customer   c          = dBCustomer.Get(reader.GetInt32(2));
                        Order      order      = new Order(reader.GetInt32(0), c);
                        OrderList.Add(order);
                    }
                }
            }
            return(OrderList);
        }