다음을 통해 공유


DataRowCollection.Find 메서드

정의

지정 PrimaryKeyDataRow 값을 사용하여 가져옵니다.

오버로드

Name Description
Find(Object[])

지정된 기본 키 값이 포함된 행을 가져옵니다.

Find(Object)

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

설명

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

Find(Object[])

Source:
DataRowCollection.cs
Source:
DataRowCollection.cs
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 지정된 기본 키 값이 들어 있는 개체입니다. 그렇지 않으면 기본 키 값이 없는 경우 null 값DataRowCollection입니다.

예외

해당 인덱스 값에 해당하는 행이 없습니다.

테이블에 기본 키가 없습니다.

예제

다음 예제에서는 배열의 값을 사용하여 개체 컬렉션 DataRow 에서 특정 행을 찾습니다. 이 메서드는 세 개의 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

설명

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

추가 정보

적용 대상

Find(Object)

Source:
DataRowCollection.cs
Source:
DataRowCollection.cs
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 입니다.

반품

지정된 기본 키 값을 포함하는 A 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

설명

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

추가 정보

적용 대상