Filtering and Sorting Data

[ Team LiB ] Recipe Filtering and Sorting Data Problem You have a DataSet filled with data, but you need to work with only a subset of the records and also to sort them. You need a way to both filter and sort the records in your DataSet without requerying the data source. | Team LiB Recipe Filtering and Sorting Data Problem You have a DataSet filled with data but you need to work with only a subset of the records and also to sort them. You need a way to both filter and sort the records in your DataSet without requerying the data source. Solution Use DataViewManager and DataView objects to filter and sort a DataSet. The sample code contains two event handlers Sets up the sample by creating a DataSet containing the Customers and Orders tables from the Northwind sample database and a relation between them. The default view for the Customers table is bound to the data grid on the form. Refresh Applies the filters and sort order specified by the user to the data views for the tables accessed through the DataViewManager object. The C code is shown in Example 3-1. Example 3-1. File Namespaces variables and constants using System using using using Table name constants private const String CUSTOMERS_TABLE Customers private const String ORDERS_TABLE Orders Relation name constants private const String CUSTOMERS_ORDERS_RELATION Customers_Orders_Relation Field name constants private const String CUSTOMERID_FIELD CustomerlD private const String ORDERID_FIELD OrderlD private const String CONTACTNAME_FIELD ContactName private DataSet ds . . . private void FilterSortForm_Load object sender e ds new DataSet SqlDataAdapter da Fill the Customers table and add it to the DataSet. da new SqlDataAdapter SELECT FROM Customers S ql_ConnectString DataTable customersTable new DataTable CUSTOMERS_TABLE customersTable customersTable Fill the Order table and add it to the DataSet. da new SqlDataAdapter SELECT FROM Orders S ql_ConnectString DataTable orderTable new DataTable ORDERS_TABLE orderTable orderTable Create a relation between the .

Bấm vào đây để xem trước nội dung
TÀI LIỆU MỚI ĐĂNG
207    561    4    22-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.