System.Data Namespace DataTable Class
Returns an array of DataRow objects.
1. Returns an array of all DataRow objects.
2. Returns an array of all DataRow objects that match the filter criteria in order of primary key ( or lacking one, order of addition. )
3. Returns an array of all DataRow objects that match the filter criteria, in the specified sort order.
4. Returns an array of all DataRow objects that match the filter in the order of the sort, that match the specified state.
The following example uses a filter expression and record state to return an array of DataRow objects.
NOTE: This example uses one of the overloaded versions of Select. For other examples that may be available, see the individual overload topics.
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