DataTableReader.GetDataTypeName(Int32) 메서드

정의

지정된 열의 데이터 형식을 나타내는 문자열을 가져옵니다.

public:
 override System::String ^ GetDataTypeName(int ordinal);
public override string GetDataTypeName (int ordinal);
override this.GetDataTypeName : int -> string
Public Overrides Function GetDataTypeName (ordinal As Integer) As String

매개 변수

ordinal
Int32

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

반환

String

열의 데이터 형식을 나타내는 문자열입니다.

예외

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

닫힌 DataTableReader의 열을 읽거나 액세스하려고 한 경우

예제

다음 콘솔 애플리케이션 필드 목록과 간단한 형식 이름만 표시 DataTable:

private static void TestGetTypeName()
{
    DataTable table = GetCustomers();
    using (DataTableReader reader = new DataTableReader(table))
    {
        for (int i = 0; i < reader.FieldCount; i++)
        {
            Console.WriteLine("{0}: {1}", reader.GetName(i),
                reader.GetDataTypeName(i));
        }
    }
    Console.WriteLine("Press Enter to finish.");
    Console.ReadLine();
}

private static DataTable GetCustomers()
{
    // Create sample Customers table, in order
    // to demonstrate the behavior of the DataTableReader.
    DataTable table = new DataTable();
    // Create two columns, ID and Name.
    DataColumn idColumn = table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Name", typeof(string ));
    // Set the ID column as the primary key column.
    table.PrimaryKey = new DataColumn[] { idColumn };

    table.Rows.Add(new object[] { 1, "Mary" });
    table.Rows.Add(new object[] { 2, "Andy" });
    table.Rows.Add(new object[] { 3, "Peter" });
    table.Rows.Add(new object[] { 4, "Russ" });
    return table;
}
Private Sub TestGetTypeName()
   Dim table As DataTable = GetCustomers()
   Using reader As New DataTableReader(table)
      For i As Integer = 0 To reader.FieldCount - 1
         Console.WriteLine("{0}: {1}", _
            reader.GetName(i), reader.GetDataTypeName(i))
      Next
   End Using

   Console.WriteLine("Press Enter to finish.")
   Console.ReadLine()
End Sub

Private Function GetCustomers() As DataTable
   ' Create sample Customers table, in order
   ' to demonstrate the behavior of the DataTableReader.
   Dim table As New DataTable

   ' Create two columns, ID and Name.
   Dim idColumn As DataColumn = table.Columns.Add("ID", _
     GetType(Integer))
   table.Columns.Add("Name", GetType(String))

   ' Set the ID column as the primary key column.
   table.PrimaryKey = New DataColumn() {idColumn}

   table.Rows.Add(New Object() {1, "Mary"})
   table.Rows.Add(New Object() {2, "Andy"})
   table.Rows.Add(New Object() {3, "Peter"})
   table.Rows.Add(New Object() {4, "Russ"})
   Return table
End Function

콘솔 창에는 다음과 같은 결과가 표시 됩니다.

ID: Int32  
Name: String  

설명

합니다 GetDataTypeName 메서드는 항상 기본 형식의 반환 DataColumn 공급자별 형식 대신 합니다.

적용 대상