This documentation is archived and is not being maintained.

DataTable.Select Method (String, String)

Gets an array of all DataRow objects that match the filter criteria, in the specified sort order.

Namespace: System.Data
Assembly: System.Data (in system.data.dll)

public DataRow[] Select (
	string filterExpression,
	string sort
)
public DataRow[] Select (
	String filterExpression, 
	String sort
)
public function Select (
	filterExpression : String, 
	sort : String
) : DataRow[]
Not applicable.

Parameters

filterExpression

The criteria to use to filter the rows.

sort

A string specifying the column and sort direction.

Return Value

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.

private void GetRowsByFilter()
{
    DataTable table = DataSet1.Tables["Orders"];

    // Presuming the DataTable has a column named Date.
    string expression = "Date > '1/1/00'";

    // Sort descending by column named CompanyName.
    string sortOrder = "CompanyName DESC";
    DataRow[] foundRows;

    // Use the Select method to find all rows matching the filter.
    foundRows = table.Select(expression, sortOrder);

    // Print column 0 of each returned row.
    for(int i = 0; i < foundRows.Length; i ++)
    {
        Console.WriteLine(foundRows[i][0]);
    }
}
 

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Show: