Filtering data from a datatable

jrvbdeveloper

Member
Joined
Jul 15, 2007
Messages
17
Programming Experience
Beginner
Hi,

Lets say I have a datatable which contains 8 columns. What I need to do is iterate through the datatable a few group of rows at a time. I need to retrieve all rows that have the same colA,colB,colC,colD and do some processing. Then I need to retrieve the next group that the same colA-D and do some processing,etc.

What is the best way to accomplish this? Is it through a copy of the datatable on which I retrieve the first row and go dataTable.Select(where col=...) and after processing simply delete the records? Then look at the next record,etc? Is there an easier way to accomplish this? Note that I cant do a group by as that's not what i need.

Thanks
 
The DataTable.Select & DataView.FindRows returns an array of datarows that match your search critera.

If you want to return the results of a particular query on the data, as opposed to providing a dynamic view of a subset of the data, use the Find or FindRows methods of the DataView to achieve best performance rather than setting the RowFilter property.

Setting the RowFilter property rebuilds the index for the data, adding overhead to your application and decreasing performance. The RowFilter property is best used in a data-bound application where a bound control displays filtered results. The Find and FindRows methods leverage the current index without requiring the index to be rebuilt.

Being as a DataView is an object that acts as a layer on top of the data table, providing a filtered and sorted view of the table's contents. With the exception of needing to bind the results I think it would use less resources to use the table.select method for any processing of filtered records.

Sorting and Filtering Data (ADO.NET)
 
Last edited:
Back
Top