Select a Subset of Data from a DataSet


You want to find specific rows in a DataSet.


Use the DataTable.Select method or the DataRowCollection.Find method.


You can use several approaches to find individual DataRow objects in a DataSet. The most obvious approach is to simply iterate through the collection of DataRow objects until you find one that matches the criteria you are looking for.

Dim MatchedRows() As New ArrayList

Dim Row As DataRow
For Each Row In Ds.Tables(0).Rows
    If Row(FieldName) = FieldValue Then
    End If

However, ADO.NET also provides two more-convenient approaches. First, you can use the DataRowCollection.Find method to find a single row based on its unique primary key. For example, if ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.