Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Select Method (String)

DataTable.Select Method (String)

.NET Framework 1.1

Gets an array of all DataRow objects that match the filter criteria in order of primary key (or lacking one, order of addition.)

[Visual Basic]
Overloads Public Function Select( _
   ByVal filterExpression As String _
) As DataRow()
[C#]
public DataRow[] Select(
 string filterExpression
);
[C++]
public: DataRow* Select(
 String* filterExpression
) [];
[JScript]
public function Select(
   filterExpression : String
) : DataRow[];

Parameters

filterExpression
The criteria to use to filter the rows.

Return Value

An array of DataRow objects.

Remarks

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

Example

[Visual Basic, C#, C++] The following example uses a filter expression to return an array of DataRow objects.

[Visual Basic] 
Private Sub GetRowsByFilter()
   Dim t As DataTable
   t = DataSet1.Tables("Orders")
   ' Presuming the DataTable has a column named Date.
   Dim strExpr As String
   strExpr = "Date > '1/1/00'"
   Dim foundRows() As DataRow
   ' Use the Select method to find all rows matching the filter.
   foundRows = t.Select(strExpr)
   Dim i As Integer
   ' Print column 0 of each returned row.
   For i = 0 to foundRows.GetUpperBound(0)
      Console.WriteLine(foundRows(i)(0))
   Next i
End Sub

[C#] 
private void GetRowsByFilter(){
   DataTable myTable;
   myTable = DataSet1.Tables["Orders"];
   // Presuming the DataTable has a column named Date.
   string strExpr;
   strExpr = "Date > '1/1/00'";
   DataRow[] foundRows;
   // Use the Select method to find all rows matching the filter.
   foundRows = myTable.Select(strExpr);
   // Print column 0 of each returned row.
   for(int i = 0; i < foundRows.Length; i ++){
      Console.WriteLine(foundRows[i][0]);
   }
}

[C++] 
private:
 void GetRowsByFilter(){
    DataTable* myTable;
    myTable = DataSet1->Tables->Item[S"Orders"];
    // Presuming the DataTable has a column named Date.
    String* strExpr;
    strExpr = S"Date > '1/1/00'";
    DataRow* foundRows[];
    // Use the Select method to find all rows matching the filter.
    foundRows = myTable->Select(strExpr);
    // Print column 0 of each returned row.
    for(int i = 0; i < foundRows->Length; i ++){
       Console::WriteLine(foundRows[i]->Item[0]);
    }
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataTable Class | DataTable Members | System.Data Namespace | DataTable.Select Overload List | CaseSensitive | Expression | DataRow

Show:
© 2015 Microsoft