How to filter the data using Data View Manager in VB.NET?

Individual DataViews can be defined to sort or filter the data in each DataSet table. If the DataSet contains multiple tables, an alternative is to create a DataView manager (a DataViewManager object). The DataView manager works something like a dataset-wide
data view. It provides a single object that manages a collection of DataViews, each of which is associated with a specific table in a dataset. To use a DataView manager, the user must create and configure it in code. There is no design-time object that can be added to a form or component. This means that controls are bound to the DataView manager in code, as there is no design-time component to bind them to.
The following project will illustrate the filtering and sorting of the data.

1. Create a new Windows application project.
2. Add three labels, one DataGridView, one ComboBox and a button to the Form
3. And arrange them as shown in the screenshot below
4. Now go to the following steps.
1. Create a SqlConnection object whose constructor will take the connectString as the parameter.
2. Create SqlDataAdapter whose constructor will take the SqlStatement and the connection object as parameters.
3. Instantiating a DataSet and a DataView.
4. Call the fill method of the SqlDataAdapter and fill the DataSet.
5. Create a view.
6. To the ComboBox add the name of the table columns are to be sorted on.
7. Instantiate a DataView object that will be based on the DataSet table
8. Call the sort method of dataview from within the EventHandler of ComboBox selectedIndexChanged.
9. Press F5 to execute the code.

Posted by Mahesh ( Tryangled )

Leave a Reply

You must be logged in to post a comment.