Export (0) Print
Expand All

DataTable.Select Method (String)

Gets an array of all DataRow objects that match the filter criteria in order of primary key (or lacking one, order of addition.)

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

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

Parameters

filterExpression

The criteria to use to filter the rows.

Return Value

An array of DataRow objects.

To create the filterExpression argument, use the same rules that apply to the DataColumn class's Expression property value for creating filters.

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;
    expression = "Date > #1/1/00#";
    DataRow[] foundRows;

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

    // 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

Community Additions

ADD
Show:
© 2015 Microsoft