DataTableReader.GetGuid(Int32) 메서드

정의

지정된 열의 값을 GUID(Globally Unique Identifier)로 가져옵니다.

public:
 override Guid GetGuid(int ordinal);
public override Guid GetGuid(int ordinal);
override this.GetGuid : int -> Guid
Public Overrides Function GetGuid (ordinal As Integer) As Guid

매개 변수

ordinal
Int32

0부터 시작하는 열 서수입니다.

반품

지정된 열의 값입니다.

예외

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

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

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

지정된 열에 GUID가 없습니다.

예제

다음 예제에서는 전달된 DataTableReader 내에서 2로 번호가 매겨진 열의 내용을 표시합니다. 특정 행 내의 열 값이 null이면 코드에 텍스트 <NULL>이 표시됩니다. 열 내의 데이터가 올바른 형식이 아니면 각 행에 대한 오류 메시지가 표시됩니다.

private static void PrintColumn(DataTableReader reader)
{
    // Loop through all the rows in the DataTableReader
    while (reader.Read())
    {
        if (reader.IsDBNull(2))
        {
            Console.Write("<NULL>");
        }
        else
        {
            try
            {
                Console.Write(reader.GetGuid(2));
            }
            catch (InvalidCastException)
            {
                Console.Write("Invalid data type.");
            }
        }
        Console.WriteLine();
    }
}
Private Sub PrintColumn(ByVal reader As DataTableReader)
   ' Loop through all the rows in the DataTableReader
   While reader.Read()
      If reader.IsDBNull(2) Then
         Console.Write("<NULL>")
      Else
         Try
            Console.Write(reader.GetGuid(2))
         Catch ex As InvalidCastException
            Console.Write("Invalid data type.")
         End Try
      End If
      Console.WriteLine()
   End While
End Sub

설명

변환은 수행되지 않습니다. 따라서 검색된 데이터는 이미 />이거나 강제 변환 가능해야 합니다.

이 메서드를 호출하기 전에 null 값이 있는지 확인하기 위해 호출 IsDBNull 합니다.

적용 대상