DataTable.Select メソッド (String)
フィルタ基準と一致するすべての DataRow オブジェクトを主キーの順に (主キーがない場合は追加された順に) 配列として取得します。
Overloads Public Function Select( _
ByVal filterExpression As String _) As DataRow()
[C#]
public DataRow[] Select(stringfilterExpression);
[C++]
public: DataRow* Select(String* filterExpression) [];
[JScript]
public function Select(
filterExpression : String) : DataRow[];
パラメータ
- filterExpression
行にフィルタをかけるために使用する基準。
戻り値
DataRow オブジェクトの配列。
解説
引数 filterExpression を作成するには、フィルタを作成するときに DataColumn クラスの Expression プロパティの値に適用する規則と同じ規則を使用します。
使用例
[Visual Basic, C#, C++] フィルタ式を使用して DataRow オブジェクトの配列を返す例を次に示します。
Private Sub GetRowsByFilter()
Dim t As DataTable
t = DataSet1.Tables("Orders")
' Presuming the DataTable has a column named Date.
Dim strExpr As String
strExpr = "Date > '1/1/00'"
Dim foundRows() As DataRow
' Use the Select method to find all rows matching the filter.
foundRows = t.Select(strExpr)
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 myTable;
myTable = DataSet1.Tables["Orders"];
// Presuming the DataTable has a column named Date.
string strExpr;
strExpr = "Date > '1/1/00'";
DataRow[] foundRows;
// Use the Select method to find all rows matching the filter.
foundRows = myTable.Select(strExpr);
// Print column 0 of each returned row.
for(int i = 0; i < foundRows.Length; i ++){
Console.WriteLine(foundRows[i][0]);
}
}
[C++]
private:
void GetRowsByFilter(){
DataTable* myTable;
myTable = DataSet1->Tables->Item[S"Orders"];
// Presuming the DataTable has a column named Date.
String* strExpr;
strExpr = S"Date > '1/1/00'";
DataRow* foundRows[];
// Use the Select method to find all rows matching the filter.
foundRows = myTable->Select(strExpr);
// Print column 0 of each returned row.
for(int i = 0; i < foundRows->Length; i ++){
Console::WriteLine(foundRows[i]->Item[0]);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
DataTable クラス | DataTable メンバ | System.Data 名前空間 | DataTable.Select オーバーロードの一覧 | CaseSensitive | Expression | DataRow