Data Access: Sort and Filter with a Dataview

This sample shows some how to use a dataview to sort and filter the contents of a table of product information. 

Featured Highlights:

The code demonstrates how to use a dataview to sort and filter the contents of the products table from the Northwind SQL Server database. When the main form loads, the products table is retrived into a dataset using a simple SQL Select statement. A dataview is constructed to filter and sort the products table. The user can select filter and sort criteria and view the results in a datagrid, without having to return to the data source. Rows may be filtered by selecting those products that have a user selected first character, for example all product names that begin with C, or by the UnitsInStock column, for example all rows that have > 10 units. The rows displayed may also be sorted on a primary/secondary sort key, each sort key allowing ascending or descending ordering. The primary sort key is the UnitsInStock column and the secondary key is UnitsOnOrder column.

Requirements:

Trial or Release version of Visual Studio .NET Professional (or greater).

Access to the Northwind database residing in SQL Server or the Microsoft Data Engine (MSDE).  To install MSDE, do the following:

Running the Sample

Simply press F5.

  1. When the main form initially loads a dataset is loaded with all rows form the products table in the Northwind database. All manipulations of this product data that subsequently occur are accomplished by filtering/ sorting the disconnected copy of the product data in the dataset through usage of a dataview. The product data is not retreived from the data source after the initial load in order to satisfy any user filter/sort requests.
  2. Filter criteria specifies the subset of rows based on an expression. Expressions have a very rich syntax which can accommodate complex selection criteria.

See Also:

System.Data Namespace DataView Class Creating a DataView,  Sorting and Filtering Using a DataView