DataTable.Select メソッド ()
アセンブリ: System.Data (system.data.dll 内)

Dim instance As DataTable Dim returnValue As DataRow() returnValue = instance.Select
DataRow オブジェクトの配列。


Select メソッドを使用して DataRow オブジェクトの配列を返す例を次に示します。
Private Sub GetRows() ' Get the DataTable of a DataSet. Dim table As DataTable = DataSet1.Tables("Suppliers") Dim rows() As DataRow = table.Select() Dim i As Integer ' Print the value one column of each DataRow. For i = 0 to rows.GetUpperBound(0) Console.WriteLine(rows(i)("CompanyName")) Next i End Sub

Windows 98, Windows 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataTable.Select メソッド (String, String, DataViewRowState)
アセンブリ: System.Data (system.data.dll 内)

Public Function Select ( _ filterExpression As String, _ sort As String, _ recordStates As DataViewRowState _ ) As DataRow()
Dim instance As DataTable Dim filterExpression As String Dim sort As String Dim recordStates As DataViewRowState Dim returnValue As DataRow() returnValue = instance.Select(filterExpression, sort, recordStates)
public: array<DataRow^>^ Select ( String^ filterExpression, String^ sort, DataViewRowState recordStates )
public function Select ( filterExpression : String, sort : String, recordStates : DataViewRowState ) : DataRow[]
- recordStates
DataViewRowState 値の 1 つ。
DataRow オブジェクトの配列。

引数 filterExpression を作成するには、DataColumn クラスの Expression プロパティの値を作成するときと同じ規則を使用します。引数 Sort は、クラスの Expression 文字列を作成するときと同じ規則も使用します。

フィルタ式とレコードの状態を使用して、DataRow オブジェクトの配列を返す例を次に示します。
Private Sub GetRowsByFilter() Dim customerTable As DataTable = New DataTable("Customers") ' Add columns customerTable.Columns.Add("id", GetType(Integer)) customerTable.Columns.Add("name", GetType(String)) ' Set PrimaryKey customerTable.Columns("id").Unique = True customerTable.PrimaryKey = New DataColumn() _ {customerTable.Columns("id")} ' add ten rows Dim id As Integer For id = 1 To 10 customerTable.Rows.Add( _ New Object() {id, String.Format("customer{0}", id)}) Next id customerTable.AcceptChanges() ' add another ten rows For id = 11 To 20 customerTable.Rows.Add( _ New Object() {id, String.Format("customer{0}", id)}) Next id Dim expression As String Dim sortOrder As String expression = "id > 5" ' Sort descending by CompanyName column. sortOrder = "name DESC" ' Use the Select method to find all rows matching the filter. Dim foundRows As DataRow() = _ customerTable.Select(expression, sortOrder, _ DataViewRowState.Added) PrintRows(foundRows, "filtered rows") foundRows = customerTable.Select() PrintRows(foundRows, "all rows") End Sub Private Sub PrintRows(ByVal rows() As DataRow, ByVal label As String) Console.WriteLine("\n{0}", label) If rows.Length <= 0 Then Console.WriteLine("no rows found") Exit Sub End If Dim row As DataRow Dim column As DataColumn For Each row In rows For Each column In row.Table.Columns Console.Write("\table {0}", row(column)) Next column Console.WriteLine() Next row End Sub
private static void GetRowsByFilter() { DataTable customerTable = new DataTable("Customers"); // Add columns customerTable.Columns.Add("id", typeof(int)); customerTable.Columns.Add("name", typeof(string)); // Set PrimaryKey customerTable.Columns[ "id" ].Unique = true; customerTable.PrimaryKey = new DataColumn[] { customerTable.Columns["id"] }; // Add ten rows for(int id=1; id<=10; id++) { customerTable.Rows.Add( new object[] { id, string.Format("customer{0}", id) }); } customerTable.AcceptChanges(); // Add another ten rows for(int id=11; id<=20; id++) { customerTable.Rows.Add( new object[] { id, string.Format("customer{0}", id) }); } string expression; string sortOrder; expression = "id > 5"; // Sort descending by column named CompanyName. sortOrder = "name DESC"; // Use the Select method to find all rows matching the filter. DataRow[] foundRows = customerTable.Select(expression, sortOrder, DataViewRowState.Added); PrintRows(foundRows, "filtered rows"); foundRows = customerTable.Select(); PrintRows(foundRows, "all rows"); } private static void PrintRows(DataRow[] rows, string label) { Console.WriteLine("\n{0}", label); if(rows.Length <= 0) { Console.WriteLine("no rows found"); return; } foreach(DataRow row in rows) { foreach(DataColumn column in row.Table.Columns) { Console.Write("\table {0}", row[column]); } Console.WriteLine(); } }

Windows 98, Windows 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataTable.Select メソッド (String)
アセンブリ: System.Data (system.data.dll 内)

Dim instance As DataTable Dim filterExpression As String Dim returnValue As DataRow() returnValue = instance.Select(filterExpression)
戻り値
DataRow オブジェクトの配列。


フィルタ式を使用して 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 98, Windows 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataTable.Select メソッド

名前 | 説明 |
---|---|
DataTable.Select () | すべての DataRow オブジェクトの配列を取得します。 .NET Compact Framework によってサポートされています。 |
DataTable.Select (String) | フィルタ基準と一致するすべての DataRow オブジェクトを主キーの順に (主キーがない場合は追加された順に) 配列として取得します。 .NET Compact Framework によってサポートされています。 |
DataTable.Select (String, String) | フィルタ基準と一致するすべての DataRow オブジェクトの配列を、指定した並べ替え順で取得します。 .NET Compact Framework によってサポートされています。 |
DataTable.Select (String, String, DataViewRowState) | フィルタ基準と一致するすべての DataRow オブジェクトの配列を、指定した状態と一致する並べ替え順に取得します。 .NET Compact Framework によってサポートされています。 |

DataTable.Select メソッド (String, String)
アセンブリ: System.Data (system.data.dll 内)

Dim instance As DataTable Dim filterExpression As String Dim sort As String Dim returnValue As DataRow() returnValue = instance.Select(filterExpression, sort)
戻り値
フィルタ式と一致する DataRow オブジェクトの配列。

引数 filterExpression を作成するには、DataColumn クラスの Expression プロパティの値を作成するときと同じ規則を使用します。引数 Sort は、クラスの Expression 文字列を作成するときと同じ規則も使用します。

フィルタ式を使用して DataRow オブジェクトの配列を返す例を次に示します。
Private Sub GetRowsByFilter() Dim table As DataTable = DataSet1.Tables(0) ' Presuming the DataTable has a column named Date. Dim expression As String = "Date > 1/1/00" ' Sort descending by column named CompanyName. Dim sortOrder As String = "CompanyName DESC" Dim foundRows() As DataRow ' Use the Select method to find all rows matching the filter. foundRows = table.Select(expression, sortOrder) 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 = "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 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

