DbDataReader.GetDataTypeName(Int32) DbDataReader.GetDataTypeName(Int32) DbDataReader.GetDataTypeName(Int32) DbDataReader.GetDataTypeName(Int32) Method

定义

在派生类中重写时,获取指定列的数据类型的名称。When overridden in a derived class, gets name of the data type of the specified column.

public:
 abstract System::String ^ GetDataTypeName(int ordinal);
public abstract string GetDataTypeName (int ordinal);
abstract member GetDataTypeName : int -> string
Public MustOverride Function GetDataTypeName (ordinal As Integer) As String

参数

ordinal
Int32 Int32 Int32 Int32

从零开始的列序号。The zero-based column ordinal.

返回

数据类型的名称。The name of the data type.

实现

异常

注解

private static void GetDataTypes(String connectionString) 
{
    using (SqlConnection conn = new SqlConnection(connectionString)) 
    {
        String queryString = "Select [CourseID],[Title],[Credits] from [MySchool].[dbo].[Course]";  
        using (DbCommand command = new SqlCommand(queryString, conn)) 
        {
            conn.Open();               
            using (DbDataReader reader = command.ExecuteReader()) 
            {
                for (Int32 i = 0; i < reader.FieldCount; i++)
                {
                    Console.WriteLine("ColumnName:{0,-15}DataType:{1,-15}",reader.GetName(i),reader.GetDataTypeName(i));
                }
            }
        }
    }
}

适用于

另请参阅