public static void get_order_detail(SortedList <int, order> orders) { order o = null; SqlCommand cmd = new SqlCommand("select OrderNum, OrderDate, ProductID, Volume, Price from OrderDetails order by OrderNum, ProductId", DB.cnn()); SqlDataReader rdr = cmd.ExecuteReader(); int order_num = -1; while (rdr.Read()) { order_detail od = new order_detail(); od.order_num = (int)rdr.GetValue(0); od.order_date = (DateTime)rdr.GetValue(1); od.product_id = (int)rdr.GetValue(2); od.volume = (int)rdr.GetValue(3); od.price = (Double)rdr.GetValue(4); if (od.order_num != order_num) { orders.TryGetValue(od.order_num, out o); order_num = od.order_num; } if (o != null) { o.details.Add(od); o.OnDetailChanged(); } } rdr.Close(); }