tailieunhanh - Microsoft ADO .NET 4 Step by Step - p 13

Cũng như các đơn bảng tổng hợp, biểu thức có thể tham khảo bất kỳ cột có giá trị trong bảng con, kể cả cột biểu hiện khác. Xem xét các mã sau đây, mà tính toán tổng số đơn đặt hàng của từng khách hàng và lưu trữ các kết quả trong một cột biểu hiện trong bảng (mẹ) của khách hàng: | 96 Microsoft 4 Step by Step As with single-table aggregation the expression can reference any valid column in the child table including other expression columns. Consider the following code which calculates each customer s total orders and stores the result in an expression column in the customer parent table C ----- Build the parent table and add some data. DataTable customers new DataTable Customer ID typeof int Name typeof string new Object 1 Coho Winery new Object 2 Fourth Coffee ----- Build the child table and add some data. The Total expression column adds sales tax to the subtotal. DataTable orders new DataTable Order ID typeof int Customer typeof int Subtotal typeof decimal TaxRate typeof decimal Total typeof decimal Subtotal 1 TaxRate ----- Two sample orders for customer 1 1 for customer 2. new Object 1 1 Total new Object 2 1 Total new Object 3 2 Total ----- Link the tables within a DataSet. DataSet business new DataSet customers orders ID Customer ----- Here is the aggregate expression column. OrderTotals typeof decimal Sum ----- Display each customer s order total. foreach DataRow scanCustomer in string scanCustomer Name 0 c decimal scanCustomer OrderTotals Chapter 6 Turning Data into Information 97 Visual Basic ----- Build the parent table and add some data. Dim customers As New DataTable Customer ID GetType Integer Name GetType String 1 Coho Winery 2 Fourth Coffee ----- Build the child table and add some data. The

TÀI LIỆU MỚI ĐĂNG