DataRowCollection.Find 메서드

정의

지정된 PrimaryKey 값을 사용하여 DataRow를 가져옵니다.

오버로드

Find(Object[])

지정한 기본 키 값이 있는 행을 가져옵니다.

Find(Object)

기본 키 값으로 지정한 행을 가져옵니다.

설명

성능은 O(log n) 작업이어야 합니다.

Find(Object[])

Source:
DataRowCollection.cs
Source:
DataRowCollection.cs
Source:
DataRowCollection.cs

지정한 기본 키 값이 있는 행을 가져옵니다.

public:
 System::Data::DataRow ^ Find(cli::array <System::Object ^> ^ keys);
public System.Data.DataRow? Find (object?[] keys);
public System.Data.DataRow Find (object[] keys);
member this.Find : obj[] -> System.Data.DataRow
Public Function Find (keys As Object()) As DataRow

매개 변수

keys
Object[]

찾을 기본 키 값 배열입니다. 이 배열의 형식은 Object입니다.

반환

지정한 기본 키 값이 있는 DataRow 개체이거나, 기본 키 값이 DataRowCollection에 없으면 null 값입니다.

예외

그 인덱스 값에 일치하는 행이 없는 경우

이 테이블에 기본 키가 없는 경우

예제

다음 예제에서는 배열의 값을 사용하여 개체 컬렉션 DataRow 에서 특정 행을 찾습니다. 메서드는 3개의 DataTable 기본 키 열이 있는 가 있다고 가정합니다. 값의 배열을 만든 후 코드는 배열과 Find 함께 메서드를 사용하여 원하는 특정 개체를 가져옵니다.

private void FindInMultiPKey(DataTable table)
{
    // Create an array for the key values to find.
    object[]findTheseVals = new object[3];

    // Set the values of the keys to find.
    findTheseVals[0] = "John";
    findTheseVals[1] = "Smith";
    findTheseVals[2] = "5 Main St.";

    DataRow foundRow = table.Rows.Find(findTheseVals);
    // Display column 1 of the found row.
    if(foundRow != null)
        Console.WriteLine(foundRow[1]);
}
 Private Sub FindInMultiPKey(ByVal table As DataTable)
    ' Create an array for the key values to find.
    Dim findTheseVals(2) As Object

    ' Set the values of the keys to find.
    findTheseVals(0) = "John"
    findTheseVals(1) = "Smith"
    findTheseVals(2) = "5 Main St."

    Dim foundRow As DataRow = table.Rows.Find(findTheseVals)
    ' Display column 1 of the found row.
    If Not (foundRow Is Nothing) Then
        Console.WriteLine(foundRow(1).ToString())
    End If
End Sub

설명

메서드를 사용하려면 개체가 FindDataTable 속한 개체 DataRowCollection 에 기본 키 열로 지정된 열이 하나 이상 있어야 합니다. 둘 이상의 행에 동일한 기본 키 값이 있으면 발견된 첫 번째 행이 반환됩니다. 이 문제는 가 false로 설정된 경우에 EnforceConstraints 발생합니다. PrimaryKey 열을 만드는 PrimaryKey 방법에 대한 자세한 내용은 속성을 참조하거나 테이블에 둘 이상의 기본 키가 있는 경우 개체 배열 DataColumn 을 참조하세요.

추가 정보

적용 대상

Find(Object)

Source:
DataRowCollection.cs
Source:
DataRowCollection.cs
Source:
DataRowCollection.cs

기본 키 값으로 지정한 행을 가져옵니다.

public:
 System::Data::DataRow ^ Find(System::Object ^ key);
public System.Data.DataRow? Find (object? key);
public System.Data.DataRow Find (object key);
member this.Find : obj -> System.Data.DataRow
Public Function Find (key As Object) As DataRow

매개 변수

key
Object

찾을 DataRow의 기본 키 값입니다.

반환

지정한 기본 키 값이 있는 DataRow이거나, 기본 키가 DataRowCollection에 없으면 null 값입니다.

예외

이 테이블에 기본 키가 없는 경우

예제

다음 예제에서는 메서드를 Find 사용하여 개체 컬렉션 DataRow 에서 기본 키 값 "2"를 찾습니다. 메서드는 필요에 따라 값을 변경할 수 있는 특정 DataRow 개체를 반환합니다.

private void FindInPrimaryKeyColumn(DataTable table,
    long pkValue)
{
    // Find the number pkValue in the primary key
    // column of the table.
    DataRow foundRow = table.Rows.Find(pkValue);

    // Print the value of column 1 of the found row.
    if(foundRow != null)
        Console.WriteLine(foundRow[1]);
}
 Private Sub FindInPrimaryKeyColumn(ByVal table As DataTable, _
    ByVal pkValue As Long)
    ' Find the number pkValue in the primary key 
    ' column of the table.
    Dim foundRow As DataRow = table.Rows.Find(pkValue)

    ' Print the value of column 1 of the found row.
    If Not (foundRow Is Nothing) Then
        Console.WriteLine(foundRow(1).ToString())
    End If
End Sub

설명

메서드를 사용하려면 개체가 FindDataTable 속한 개체 DataRowCollection 에 기본 키 열로 지정된 열이 하나 이상 있어야 합니다. PrimaryKey 기본 키 열을 만드는 방법에 대한 자세한 내용은 속성을 참조하세요.

추가 정보

적용 대상