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에서 1까지 FieldCount 의 범위를 벗어났습니다.

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

닫힌 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

설명

이 메서드를 호출하기 전에 null 값이 있는지 확인하기 위해 호출 IsDBNull 할 수 있지만 이 작업을 수행할 필요는 없습니다.

적용 대상