DataTable.Select DataTable.Select DataTable.Select DataTable.Select Method

정의

DataRow 개체의 배열을 가져옵니다.Gets an array of DataRow objects.

오버로드

Select() Select() Select() Select()

모든 DataRow 개체의 배열을 가져옵니다.Gets an array of all DataRow objects.

Select(String) Select(String) Select(String) Select(String)

필터 조건에 맞는 모든 DataRow 개체의 배열을 가져옵니다.Gets an array of all DataRow objects that match the filter criteria.

Select(String, String) Select(String, String) Select(String, String) Select(String, String)

필터 조건에 맞는 모든 DataRow 개체의 배열을 지정된 정렬 순서대로 가져옵니다.Gets an array of all DataRow objects that match the filter criteria, in the specified sort order.

Select(String, String, DataViewRowState) Select(String, String, DataViewRowState) Select(String, String, DataViewRowState) Select(String, String, DataViewRowState)

필터와 일치하는 모든 DataRow 개체의 배열을 지정된 상태와 일치하는 정렬 순서대로 가져옵니다.Gets an array of all DataRow objects that match the filter in the order of the sort that match the specified state.

Select() Select() Select() Select()

모든 DataRow 개체의 배열을 가져옵니다.Gets an array of all DataRow objects.

public:
 cli::array <System::Data::DataRow ^> ^ Select();
public System.Data.DataRow[] Select ();
member this.Select : unit -> System.Data.DataRow[]
Public Function Select () As DataRow()

반환

DataRow 개체의 배열입니다.An array of DataRow objects.

예제

다음 예제에서는 배열을 반환 DataRow 를 통해 개체를 Select 메서드.The following example returns an array of DataRow objects through the Select method.

private void GetRows()
{
    // Get the DataTable of a DataSet.
    DataTable table = DataSet1.Tables["Suppliers"];
    DataRow[] rows = table.Select();

    // Print the value one column of each DataRow.
    for(int i = 0; i < rows.Length ; i++)
    {
        Console.WriteLine(rows[i]["CompanyName"]);
    }
}
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

설명

적절 한 정렬 순서를 지정 정렬 조건 Select(String, String) 또는 Select(String, String, DataViewRowState)합니다.To ensure the proper sort order, specify sort criteria with Select(String, String) or Select(String, String, DataViewRowState).

추가 정보

Select(String) Select(String) Select(String) Select(String)

필터 조건에 맞는 모든 DataRow 개체의 배열을 가져옵니다.Gets an array of all DataRow objects that match the filter criteria.

public:
 cli::array <System::Data::DataRow ^> ^ Select(System::String ^ filterExpression);
public System.Data.DataRow[] Select (string filterExpression);
member this.Select : string -> System.Data.DataRow[]
Public Function Select (filterExpression As String) As DataRow()

매개 변수

filterExpression
String String String String

행을 필터링하기 위해 사용하는 조건입니다.The criteria to use to filter the rows. 예를 들어, 행을 필터링하는 방법은 DataView RowFilter 구문 [C#]을 참조하세요.For examples on how to filter rows, see DataView RowFilter Syntax [C#].

반환

DataRow 개체의 배열입니다.An array of DataRow objects.

예제

배열을 반환 하도록 필터 식을 사용 하는 다음 예제에서는 DataRow 개체입니다.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]);
    }
}
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

설명

만들려면를 filterExpression 인수에 적용 되는 동일한 규칙을 사용 합니다 DataColumn 클래스의 Expression 필터 만들기에 대 한 속성 값.To create the filterExpression argument, use the same rules that apply to the DataColumn class's Expression property value for creating filters.

적절 한 정렬 순서를 지정 정렬 조건 Select(String, String) 또는 Select(String, String, DataViewRowState)합니다.To ensure the proper sort order, specify sort criteria with Select(String, String) or Select(String, String, DataViewRowState).

열 필터에 null 값이 있으면 결과 포함 되지 않습니다.If the column on the filter contains a null value, it will not be part of the result.

추가 정보

Select(String, String) Select(String, String) Select(String, String) Select(String, String)

필터 조건에 맞는 모든 DataRow 개체의 배열을 지정된 정렬 순서대로 가져옵니다.Gets an array of all DataRow objects that match the filter criteria, in the specified sort order.

public:
 cli::array <System::Data::DataRow ^> ^ Select(System::String ^ filterExpression, System::String ^ sort);
public System.Data.DataRow[] Select (string filterExpression, string sort);
member this.Select : string * string -> System.Data.DataRow[]
Public Function Select (filterExpression As String, sort As String) As DataRow()

매개 변수

filterExpression
String String String String

행을 필터링하기 위해 사용하는 조건입니다.The criteria to use to filter the rows. 예를 들어, 행을 필터링하는 방법은 DataView RowFilter 구문 [C#]을 참조하세요.For examples on how to filter rows, see DataView RowFilter Syntax [C#].

sort
String String String String

열과 정렬 방향을 지정하는 문자열입니다.A string specifying the column and sort direction.

반환

필터 식에 맞는 DataRow 개체의 배열을 반환합니다.An array of DataRow objects matching the filter expression.

예제

배열을 반환 하도록 필터 식을 사용 하는 다음 예제에서는 DataRow 개체입니다.The following example uses a filter expression to return an array of DataRow objects.

using System;
using System.Data;

public class A {  

   public static void Main() {      
      DataTable table = new DataTable("Orders");
      table.Columns.Add("OrderID", typeof(Int32));
      table.Columns.Add("OrderQuantity", typeof(Int32));
      table.Columns.Add("CompanyName", typeof(string));      
      table.Columns.Add("Date", typeof(DateTime));

      DataRow newRow = table.NewRow();
      newRow["OrderID"] = 1;
      newRow["OrderQuantity"] = 3;
      newRow["CompanyName"] = "NewCompanyName";
      newRow["Date"] = "1979, 1, 31";

      // Add the row to the rows collection.
      table.Rows.Add(newRow);
      
      DataRow newRow2 = table.NewRow();
      newRow2["OrderID"] = 2;
      newRow2["OrderQuantity"] = 2;
      newRow2["CompanyName"] = "NewCompanyName1";
      table.Rows.Add(newRow2);

      DataRow newRow3 = table.NewRow();
      newRow3["OrderID"] = 3;
      newRow3["OrderQuantity"] = 2;
      newRow3["CompanyName"] = "NewCompanyName2";
      table.Rows.Add(newRow3);

      // Presuming the DataTable has a column named Date.
      string expression = "Date = '1/31/1979' or OrderID = 2";
      // string expression = "OrderQuantity = 2 and OrderID = 2";

      // Sort descending by column named CompanyName.
      string sortOrder = "CompanyName ASC";
      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][2]);
   }
}
Imports System.Data

Public Class A

   Public Shared Sub Main()
      Dim table As New DataTable("Orders")
      table.Columns.Add("OrderID", GetType(Int32))
      table.Columns.Add("OrderQuantity", GetType(Int32))
      table.Columns.Add("CompanyName", GetType(String))
      table.Columns.Add("Date", GetType(DateTime))

      Dim newRow As DataRow = table.NewRow()
      newRow("OrderID") = 1
      newRow("OrderQuantity") = 3
      newRow("CompanyName") = "NewCompanyName"
      newRow("Date") = "1979, 1, 31"

      ' Add the row to the rows collection.
      table.Rows.Add(newRow)

      Dim newRow2 As DataRow = table.NewRow()
      newRow2("OrderID") = 2
      newRow2("OrderQuantity") = 2
      newRow2("CompanyName") = "NewCompanyName1"
      table.Rows.Add(newRow2)

      Dim newRow3 As DataRow = table.NewRow()
      newRow3("OrderID") = 3
      newRow3("OrderQuantity") = 2
      newRow3("CompanyName") = "NewCompanyName2"
      table.Rows.Add(newRow3)

      ' Presuming the DataTable has a column named Date.
      Dim expression As String = "Date = '1/31/1979' or OrderID = 2"
      ' Dim expression As String = "OrderQuantity = 2 and OrderID = 2"

      ' Sort descending by column named CompanyName.
      Dim sortOrder As String = "CompanyName ASC"
      Dim foundRows As DataRow()

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

      ' Print column 0 of each returned row.
      For i As Integer = 0 To foundRows.Length - 1
         Console.WriteLine(foundRows(i)(2))
      Next
   End Sub
End Class

설명

폼에는 filterExpression 인수를 만들기에 대 한 동일한 규칙을 사용 합니다 DataColumn 클래스의 Expression 속성 값입니다.To form the filterExpression argument, use the same rules for creating the DataColumn class's Expression property value. 합니다 Sort 클래스의 만들기에 대 한 인수 또한 사용 하 여 동일한 규칙 Expression 문자열입니다.The Sort argument also uses the same rules for creating class's Expression strings.

열 필터에 null 값이 있으면 결과 포함 되지 않습니다.If the column on the filter contains a null value, it will not be part of the result.

추가 정보

Select(String, String, DataViewRowState) Select(String, String, DataViewRowState) Select(String, String, DataViewRowState) Select(String, String, DataViewRowState)

필터와 일치하는 모든 DataRow 개체의 배열을 지정된 상태와 일치하는 정렬 순서대로 가져옵니다.Gets an array of all DataRow objects that match the filter in the order of the sort that match the specified state.

public:
 cli::array <System::Data::DataRow ^> ^ Select(System::String ^ filterExpression, System::String ^ sort, System::Data::DataViewRowState recordStates);
public System.Data.DataRow[] Select (string filterExpression, string sort, System.Data.DataViewRowState recordStates);
member this.Select : string * string * System.Data.DataViewRowState -> System.Data.DataRow[]
Public Function Select (filterExpression As String, sort As String, recordStates As DataViewRowState) As DataRow()

매개 변수

filterExpression
String String String String

행을 필터링하기 위해 사용하는 조건입니다.The criteria to use to filter the rows. 예를 들어, 행을 필터링하는 방법은 DataView RowFilter 구문 [C#]을 참조하세요.For examples on how to filter rows, see DataView RowFilter Syntax [C#].

sort
String String String String

열과 정렬 방향을 지정하는 문자열입니다.A string specifying the column and sort direction.

반환

DataRow 개체의 배열입니다.An array of DataRow objects.

예제

다음 예제에서는 필터 식과 레코드 상태를 사용 하 여 배열을 반환할 DataRow 개체입니다.The following example uses a filter expression and record state to return an array of DataRow objects.

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();
    }
}
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

설명

폼에는 filterExpression 인수를 만들기에 대 한 동일한 규칙을 사용 합니다 DataColumn 클래스의 Expression 속성 값입니다.To form the filterExpression argument, use the same rules for creating the DataColumn class's Expression property value. 합니다 Sort 클래스의 만들기에 대 한 인수 또한 사용 하 여 동일한 규칙 Expression 문자열입니다.The Sort argument also uses the same rules for creating class's Expression strings.

열 필터에 null 값이 있으면 결과 포함 되지 않습니다.If the column on the filter contains a null value, it will not be part of the result.

추가 정보

적용 대상