# Using Expression Columns to Display Aggregate Values

Chia sẻ: Bui Tuan | Ngày: | Loại File: PDF | Số trang:3

0
54
lượt xem
4

## Using Expression Columns to Display Aggregate Values

Mô tả tài liệu
Download Vui lòng tải xuống để xem tài liệu đầy đủ

[ Team LiB ] Recipe 3.7 Using Expression Columns to Display Aggregate Values Problem You want to add summary information such as averages, sums, and counts to a table based on related child rows. Solution Use expression columns to perform aggregate calculations based on child rows.

Chủ đề:

Bình luận(0)

Lưu

## Nội dung Text: Using Expression Columns to Display Aggregate Values

1. [ Team LiB ] Recipe 3.7 Using Expression Columns to Display Aggregate Values Problem You want to add summary information such as averages, sums, and counts to a table based on related child rows. Solution Use expression columns to perform aggregate calculations based on child rows. The sample code starts by creating a DataSet containing the Orders and Order Details tables from Northwind sample database and a relation between them. An expression is added to the Order Details table to calculate the extended price for each row. Aggregate values for the total extended price of the order and the number of Order Detail rows are added to the Orders table. Finally, the default view of the Orders table is bound to the data grid to display the results. The C# code is shown in Example 3-7. Example 3-7. File: ChildAggregateForm.cs // Namespaces, variables, and constants using System; using System.Configuration; using System.Data; using System.Data.SqlClient; // Table name constants private const String ORDERS_TABLE = "Orders"; private const String ORDERDETAILS_TABLE = "OrderDetails"; // Relation name constants private const String ORDERS_ORDERDETAILS_RELATION = "Orders_OrderDetails_Relation"; // Field name constants private const String ORDERID_FIELD = "OrderID";