Search This Blog

Wednesday, October 24, 2012

DataTable.Select Method (String) c#

C# > Data   > DataTable > Select

DataTable Select method gets an array of all DataRow objects that match the filter criteria.
If the column on the filter contains a null value, it will not be part of the result.

Example:

private void FilterDataTable(string filter)
{
    DataTable table = DataSet1.Tables["Person"];
    DataRow[] foundRows;

    // Use the Select method to find all rows matching the filter. Sample: filter = "name = 'dan' "
    foundRows = table.Select(expression);
    for(int i = 0; i < foundRows.Length; i ++)
    {
        Console.WriteLine(foundRows[i][0] );
    }
}