.NET Framework 類別庫
DataTable..::.Select 方法 (String)

更新:2007 年 11 月

取得符合按照主索引鍵順序 (如果沒有,則使用加法順序) 的篩選準則的所有 DataRow 物件之陣列。

命名空間:  System.Data
組件:  System.Data (在 System.Data.dll 中)
語法

Visual Basic (宣告)
Public Function Select ( _
    filterExpression As String _
) As DataRow()
Visual Basic (使用方式)
Dim instance As DataTable
Dim filterExpression As String
Dim returnValue As DataRow()

returnValue = instance.Select(filterExpression)
C#
public DataRow[] Select(
    string filterExpression
)
Visual C++
public:
array<DataRow^>^ Select(
    String^ filterExpression
)
J#
public DataRow[] Select(
    String filterExpression
)
JScript
public function Select(
    filterExpression : String
) : DataRow[]

參數

filterExpression
型別:System..::.String
用來篩選資料列的準則。

傳回值

型別:array<System.Data..::.DataRow>[]()[]
DataRow 物件的陣列。
備註

若要建立 filterExpression 引數,請使用與套用至 DataColumn 類別的 Expression 屬性值相同的規則來建立篩選條件。

範例

下列範例會使用篩選條件運算式來傳回 DataRow 物件的陣列。

Visual Basic
Private Sub GetRowsByFilter()

    Dim table As DataTable = DataSet1.Tables("Orders")

    ' Presuming the DataTable has a column named Date.
    Dim expression As String
    expression = "Date > #1/1/00#"
    Dim foundRows() As DataRow

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

    Dim i As Integer
    ' Print column 0 of each returned row.
    For i = 0 to foundRows.GetUpperBound(0)
       Console.WriteLine(foundRows(i)(0))
    Next i
End Sub
C#
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 Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360

.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求
版本資訊

.NET Framework

支援版本:3.5、3.0、2.0、1.1、1.0

.NET Compact Framework

支援版本:3.5、2.0、1.0

XNA Framework

支援版本:1.0
請參閱

參考

其他資源

標記 :


Page view tracker