SqlDataReader.GetValues(Object[]) 메서드

정의

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

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

매개 변수

values
Object[]

특성 열을 복사해 올 Object의 배열입니다.

반환

배열에 포함된 Object 인스턴스의 수입니다.

구현

예제

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

private static void TestGetValues(SqlDataReader reader)
{
    // Given a SqlDataReader, 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 SqlDataReader)

    ' Given a SqlDataReader, 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

설명

이 메서드는 대부분의 애플리케이션에 대 한 각 열을 개별적으로 검색 하는 대신 모든 열을 검색는 효율적인 방법을 제공 합니다.

결과 행에 Object 포함된 열 수보다 적은 배열을 전달할 수 있습니다. 배열이 보유하는 Object 데이터의 양만 배열에 복사됩니다. 길이가 결과 행에 Object 포함된 열 수보다 많은 배열을 전달할 수도 있습니다.

이 메서드는 null 데이터베이스 열에 대해서는 DBNull을 반환합니다.

적용 대상

추가 정보