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(); } }
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); }