See below:
--
W.G. Ryan MVP Windows - Embedded
Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
Joe Au said:
I use data adapter to fill up data set. How can I count the no. of record,
which matches a specific condition,
In general you can walk through the datatable either of two ways
foreach(DataRow dro in dataTable.Rows){
if(Whatever)counter++;
}
or
for(int i = 0; i < dataTable.Rows; i++){
//same thing here
}
of a data table in a data set? And how
can I loop through the data table?
now, those two methods will get you through the datable generically. You
can use the DataTables.Select method to return an array of rows which match
a specifc criteria.
http://www.knowdotnet.com/articles/expressions.html
you could create a dataView, set the rowfilter to that specific filter and
then just walk through the data view
http://www.knowdotnet.com/articles/iteratingdataview.html If you set the
Rowfilter
http://www.knowdotnet.com/articles/advancedrowfilter.html then the
number of rows in the view will be exactly the number available that match
the criteria. Similarly you can use the .Find method
http://www.knowdotnet.com/articles/adopartiii.html which is a pretty good
method if you want to find on a composite key field for instance.
nonetheless, the DataTable's .Compute method
http://www.knowdotnet.com/articles/expressions.html allows you to run an
Aggregate fucntion (COUNT, SUM, AVG) locally on the datatable and its second
parameter is a filter condition so it will do what you want with only one
line of code.
HTH,
Bill