更新:2007 年 11 月
取得符合按照主索引鍵順序 (如果沒有,則使用加法順序) 的篩選準則的所有 DataRow 物件之陣列。
命名空間:
System.Data
組件:
System.Data (在 System.Data.dll 中)
Public Function Select ( _
filterExpression As String _
) As DataRow()
Dim instance As DataTable
Dim filterExpression As String
Dim returnValue As DataRow()
returnValue = instance.Select(filterExpression)
public DataRow[] Select(
string filterExpression
)
public:
array<DataRow^>^ Select(
String^ filterExpression
)
public DataRow[] Select(
String filterExpression
)
public function Select(
filterExpression : String
) : DataRow[]
若要建立 filterExpression 引數,請使用與套用至 DataColumn 類別的 Expression 屬性值相同的規則來建立篩選條件。
下列範例會使用篩選條件運算式來傳回 DataRow 物件的陣列。
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
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
參考
其他資源