DataTableReader.GetValues(Object[]) 메서드

정의

개체 배열을 현재 행의 열 값으로 채웁니다.

public:
 override int GetValues(cli::array <System::Object ^> ^ values);
public override int GetValues(object[] values);
override this.GetValues : obj[] -> int
Public Overrides Function GetValues (values As Object()) As Integer

매개 변수

values
Object[]

에서 열 값을 복사할 배열 Object 입니다 DataTableReader.

반품

배열에 복사된 열 값의 수입니다.

예외

전달된 인덱스가 0에서 1까지 FieldCount 의 범위를 벗어났습니다.

삭제된 행에서 데이터를 검색하려고 했습니다.

닫힌 DataTableReader 열의 열을 읽거나 액세스하려고 했습니다.

예제

다음 예제에서는 올바른 크기의 배열을 사용하여 제공된 DataTableReader현재 행의 모든 값을 읽는 방법을 보여 줍니다. 또한 이 샘플에서는 사용 가능한 열 수보다 작거나 클 수 있는 고정 크기 배열을 사용하는 방법을 보여 줍니다.

private static void TestGetValues(DataTableReader reader)
{
    // Given a DataTableReader, use the GetValues
    // method to retrieve a full row of data.
    // Test the GetValues method, passing in an array large
    // enough for all the columns.
    Object[] values = new Object[reader.FieldCount];
    int fieldCount = reader.GetValues(values);

    Console.WriteLine("reader.GetValues retrieved {0} columns.",
        fieldCount);
    for (int i = 0; i < fieldCount; i++)
        Console.WriteLine(values[i]);

    Console.WriteLine();

    // Now repeat, using an array that may contain a different
    // number of columns than the original data. This should work correctly,
    // whether the size of the array is larger or smaller than
    // the number of columns.

    // Attempt to retrieve three columns of data.
    values = new Object[3];
    fieldCount = reader.GetValues(values);
    Console.WriteLine("reader.GetValues retrieved {0} columns.",
        fieldCount);
    for (int i = 0; i < fieldCount; i++)
        Console.WriteLine(values[i]);
}
Private Sub TestGetValues(ByVal reader As DataTableReader)

    ' Given a DataTableReader, use the GetValues
    ' method to retrieve a full row of data.

    ' Test the GetValues method, passing in an array large
    ' enough for all the columns.
    Dim values(reader.FieldCount - 1) As Object
    Dim fieldCount As Integer = reader.GetValues(values)
    Console.WriteLine("reader.GetValues retrieved {0} columns.", _
         fieldCount)
    For i As Integer = 0 To fieldCount - 1
        Console.WriteLine(values(i))
    Next

    Console.WriteLine()

    ' Now repeat, using an array that may contain a different 
    ' number of columns than the original data. This should work correctly,
    ' whether the size of the array is larger or smaller than 
    ' the number of columns.

    ' Attempt to retrieve three columns of data.
    ReDim values(2)
    fieldCount = reader.GetValues(values)
    Console.WriteLine("reader.GetValues retrieved {0} columns.", _
         fieldCount)
    For i As Integer = 0 To fieldCount - 1
        Console.WriteLine(values(i))
    Next
End Sub

설명

대부분의 애플리케이션에서 이 메서드는 각 열을 개별적으로 검색하는 대신 모든 열을 검색하는 효율적인 방법을 제공합니다. 내 행 DataTableReader에서 모든 열 값을 검색하려는 경우 메서드는 GetValues 가장 효율적인 솔루션을 제공합니다.

결과 행에 Object 포함된 열 수보다 적은 배열을 전달할 수 있습니다. 배열에서 보유할 수 있는 Object 데이터 양만 배열에 복사됩니다. 길이가 결과 행에 포함된 열 수보다 많은 배열을 전달할 Object 수도 있습니다. 이 경우 메서드 호출에 의해 추가 배열 요소가 변경되지 않은 상태로 유지됩니다.

이 메서드는 DBNull null 열의 출력 배열에 배치됩니다.

적용 대상