Advice on filtering and using a Data View

  • Thread starter Thread starter Willie Neal
  • Start date Start date
W

Willie Neal

Using vb.net, I created a data view and would like to filter the view and
determine if a record or group of records exists. My question..........is
there a property I can check to determine if the view contains records
meeting my criteria after filtering is performed? Also if the view does in
fact contain records, is there a way to loop through view to get certain
field values from it?


Wil.
 
Yes to both questions...

Let's say I have a DataTable populated with all the authors from the
SQL Server authors table in the pubs database, and I set the Table
property of my DataView to this table.

Next, I set a filter to see only authors from the state of California:

dv.RowFilter = "state = 'CA'";

Then I can get a count of authors from CA with:

int count = dv.Count;

and I can loop through the records and print out the au_id field of
California authors with:

foreach(DataRowView drv in dv)
{
Console.WriteLine(drv["au_id"]);
}

HTH,
 
Back
Top