This documentation is archived and is not being maintained.

DataTableReader.GetDataTypeName Method

Gets a string representing the data type of the specified column.

Namespace:  System.Data
Assembly:  System.Data (in System.Data.dll)

public override string GetDataTypeName(
	int ordinal


Type: System.Int32
The zero-based column ordinal.

Return Value

Type: System.String
A string representing the column's data type.




The index passed was outside the range of 0 to FieldCount - 1.


An attempt was made to read or access a column in a closed DataTableReader.

The GetDataTypeName method always returns the type of the underlying DataColumn instead of a provider-specific type.

The following console application displays a list of fields and their type names from a simple 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), 
    Console.WriteLine("Press Enter to finish.");

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;

The Console window displays the following results:

ID: Int32
Name: String

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.