Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering problems 1

Status
Not open for further replies.

almi

Programmer
Jun 19, 2001
16
YU
I have created an SQL Connection, than a DataAdapter which fills a dataset, and now the problem: how do i filter records in the dataset without requering the database? In vb6 the job was done by recordset.filter property how do i do it in ADO.Net
 
To filter your data, you can either create a DataView object, or use the Select() method of the DataTable class.

Select() returns an array of DataRow objects. Here's a partial sample of how to use this feature:

Dim cn as SqlConnection
Dim da as SqlDataAdapter
Dim ds as DataSet
Dim row as DataRow
Dim myRows() as DataRow
|
'Make your connection
'Create your DataAdapter
'Fill your DataSet
|
myRows = ds.Tables("Customers").Select("type='retail'", "name ASC")

For Each row in myRows
'processing here
Next

This will return all the rows in the "Customers" DataTable that have a "type" of "retail" sorted by "name."

Here's how use a DataView object to filter data:

'Dim and instantiate your Connection, DataAdapter, DataSet objects as before.
Dim myDataView as DataView
Dim myRow as DataRowView

myDataView = ds.Tables("Customers").DefaultView
myDataView.RowFilter = "type='retail'"
myDataView.Sort = "name ASC"

For Each myRow in myDataView
'etc...


hth
Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top