System.Data Namespace DataTable Class
Returns an array of all DataRow objects that match the filter criteria, in the the specified sort order.
[ VB ]
Overloads Public Function Select ( _
ByVal filterExpression As String, _
ByVal sort As String _
) As DataRow ( )
[ C# ]
public DataRow [ ] Select (
string filterExpression,
string sort
);
[ C++ ]
public: DataRow* Select (
String* filterExpression,
String* sort
) [ ];
[ JScript ]
public function Select (
filterExpression : String,
sort : String
) : DataRow [ ];
- filterExpression
- The criteria to use to filter the rows.
- sort
- A string specifying the column and sort direction.
An array of DataRow objects matching the filter expression.
To form the filterExpression argument, use the same rules for creating the DataColumn class's Expression property value. The Sort argument also uses the same rules for creating class's Expression strings.
The following example uses a filter expression to return an array of DataRow objects, in the specified sort order.
private void GetRowsByFilter ( )
// presuming the DataTable has a column named Date.
string strExpr = "Date > '1/1/00'";
// sort descending by column named CompanyName.
string strSort = "CompanyName DESC";
DataTable myTable = myDataSet.Tables [ "Orders" ];
// use the Select method to find all rows matching the filter.
DataRow [ ] foundRows = myTable.Select ( strExpr, strSort );
// print column 0 of each returned row.
for ( i = 0; i < foundRows.Length; i ++ ) {
Response.Write ( foundRows [ ] [ 0 ] );
}
}
Private Sub GetRowsByFilter ( )
' presuming the DataTable has a column named Date.
Dim strExpr As String = "Date > '1/1/00'"
' sort descending by column named CompanyName.
Dim strSort As String = "CompanyName DESC"
Dim myTable As DataTable = myDataSet.Tables ( 0 )
' Use the Select method to find all rows matching the filter.
Dim foundRows ( ) As DataRow = myTable.Select ( strExpr, strSort )
Dim i As Integer
' print column 0 of each returned row.
For i = 0 to Ubound ( foundRows )
Response.Write ( foundRows ( i ) ( 0 ) )
Next i
End Sub |
|
C# |
VB |
DataTable Members DataTable.Select Overload List CaseSensitive Expression DataRow