System.Data Namespace DataTable Class
Returns an array of all DataRow objects that match the filter in the order of the sort, that match the specified state.
[ VB ]
Overloads Public Function Select ( _
ByVal filterExpression As String, _
ByVal sort As String, _
ByVal recordStates As DataViewRowState _
) As DataRow ( )
[ C# ]
public DataRow [ ] Select (
string filterExpression,
string sort,
DataViewRowState recordStates
);
[ C++ ]
public: DataRow* Select (
String* filterExpression,
String* sort,
DataViewRowState recordStates
) [ ];
[ JScript ]
public function Select (
filterExpression : String,
sort : String,
recordStates : DataViewRowState
) : DataRow [ ];
- filterExpression
- The criteria to use to filter the rows.
- sort
- A string specifying the column and sort direction.
- recordStates
- One of the DataViewRowState values.
An array of DataRow objects.
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 and record state to return an array of DataRow objects.
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";
// get only new records.
DataViewRowState recState = DataViewRowState.New;
DataTable myTable = myDataSet.Tables [ "Orders" ];
// use the Select method to find all rows matching the filter.
DataRow foundRows = myTable.Select ( strExpr, strSort, recState );
// 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"
' get only new records.
Dim recState As DataViewRowState = DataViewRowState.New
Dim myTable As DataTable = myDataSet.Tables ( "Orders" )
' Use the Select method to find all rows matching the filter.
Dim foundRows ( ) As DataRow = myTable.Select ( strExpr, strSort, recState )
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 DataRow DataView DataViewRowState Expression