DataTableReader.GetValue(Int32) 메서드

정의

지정된 열의 값을 네이티브 형식으로 가져옵니다.

public:
 override System::Object ^ GetValue(int ordinal);
public override object GetValue (int ordinal);
override this.GetValue : int -> obj
Public Overrides Function GetValue (ordinal As Integer) As Object

매개 변수

ordinal
Int32

열 서수(0부터 시작)입니다.

반환

지정된 열의 값입니다. 이 메서드는 null 열에 대해 DBNull을 반환합니다.

예외

전달된 인덱스가 0에서 FieldCount - 1 사이의 범위에 속하지 않는 경우

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

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

예제

다음 예에서는 현재 행에 있는 모든 열의 반복을 DataTableReader, 각 열 및 열 이름을의 내용을 표시 합니다. 일반적으로 하 여 검색할 행 안의 모든 열을 사용 하는 경우는 DataTableReader를 사용 하는 것이 좋습니다는 GetValues 메서드 대신 효율적 이기 때문에 합니다.

private static void GetAllValues(DataTableReader reader)
{
    // Given a DataTableReader, retrieve the value of
    // each column, and display the name, value, and type.
    // Make sure you have called reader.Read at least once before
    // calling this procedure.

    // Loop through all the columns.
    object value = null;
    for (int i = 0; i < reader.FieldCount; i++)
    {
        if (reader.IsDBNull(i))
        {
            value = "<NULL>";
        }
        else
        {
            value = reader.GetValue(i);
        }
        Console.WriteLine("{0}: {1} ({2})", reader.GetName(i),
            value, reader.GetFieldType(i).Name);
    }
}
Private Sub GetAllValues(ByVal reader As DataTableReader)

   ' Given a DataTableReader, retrieve the value of 
   ' each column, and display the name, value, and type.
   ' Make sure you've called reader.Read at least once before
   ' calling this procedure.
   ' Loop through all the columns.
   Dim value As Object
   For i As Integer = 0 To reader.FieldCount - 1
      If reader.IsDBNull(i) Then
         value = "<NULL>"
      Else
         value = reader.GetValue(i)
      End If
      Console.WriteLine("{0}: {1} ({2})", reader.GetName(i), _
         value, reader.GetFieldType(i).Name)
   Next
End Sub

설명

호출할 수 있지만 IsDBNull 보려면이 메서드를 호출 하기 전에 null 값이 있는 경우이 작업을 수행할 필요가 없습니다.

적용 대상