Database Reference
In-Depth Information
Note If you want to prove this for yourself, simply open the connection in FilterSort before calling Fill()
and then display the value of the connection's State property. It will be Open . Comment out the Open() call, and
run it again. State will be closed.
Using Data Views
In the previous example, you saw how to dynamically filter and sort data in a data table using the Select
method. However, ADO.NET has another approach for doing much the same thing and more: data
views. A data view (an instance of the class System.Data.DataView ) enables you to create dynamic views
of the data stored in an underlying data table, reflecting all the changes made to its content and its
ordering. This differs from the Select method, which returns an array of data rows whose contents
reflect the changes to data values but not the data ordering.
Note A data view is a dynamic representation of the contents of a data table. Like a SQL view, it doesn't
actually hold data.
Try It: Refining Data with a Data View
We won't cover all aspects of data views here, because they're beyond the scope of this topic. However,
to show how they can be used, we'll present a short example that uses a data view to dynamically sort
and filter an underlying data table.
1. Select the DataSetandDataAdapter project, right-click, and choose Add
Windows Form. From the opened dialog, make sure the Windows form is
selected and rename Form1.cs to DataViews.cs . Click OK to add this form to
the DataSetandDataAdapter project.
2. Select the DataViews form by clicking the form's title bar, and set the Size
property's Width to 304 and Height to 359.
3. Drag a GridView control to the form, and position it toward the center of the
form. Select this GridView control, navigate to the Properties window, and set
the following properties:
Set the Name property to gvContact.
For the Location property, set X to 12 and Y to 12.
Set the ScrollBars property to Vertical.
For the Size property, set Width to 262 and Height to 298.
4. Now your FilterSort form in the Design view should look like Figure 15-7.
 
Search WWH ::




Custom Search