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에서 FieldCount - 1 사이의 범위에 속하지 않는 경우

삭제된 행에서 데이터를 검색하려고 한 경우

닫힌 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 열에 대 한 출력 배열입니다.

적용 대상