DataTable.Select Method (String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets an array of all DataRow objects that match the filter criteria.

Namespace:   System.Data
Assembly:  System.Data (in System.Data.dll)

Public Function Select (
	filterExpression As String
) As DataRow()


Type: System.String

The criteria to use to filter the rows. For examples on how to filter rows, see DataView RowFilter Syntax [C#].

Return Value

Type: System.Data.DataRow()

An array of DataRow objects.

To create the filterExpression argument, use the same rules that apply to the DataColumn class's Expression property value for creating filters.

To ensure the proper sort order, specify sort criteria with Select or Select.

If the column on the filter contains a null value, it will not be part of the result.

The following example uses a filter expression to return an array of DataRow objects.

Private Sub GetRowsByFilter()

    Dim table As DataTable = DataSet1.Tables("Orders")

    ' Presuming the DataTable has a column named Date.
    Dim expression As String
    expression = "Date > #1/1/00#"
    Dim foundRows() As DataRow

    ' Use the Select method to find all rows matching the filter.
    foundRows = table.Select(expression)

    Dim i As Integer
    ' Print column 0 of each returned row.
    For i = 0 to foundRows.GetUpperBound(0)
    Next i
End Sub

.NET Framework
Available since 1.1
Return to top