获取数据表列数据类型数据类型、数据表

2023-09-04 02:06:07 作者:动我姐妹全撂倒

  DataTable的DT =新的DataTable();
dt.Columns.Add(新的DataColumn(gridColumn1的typeof(布尔)));
 

我期待此行的结果,包括对DataColumns类型(布尔)的信息:

 ?dt.Columns [0] .GetType()
 

解决方案 excel如何读取B列的数据类型和b列里的数据

您想用什么这个属性是:

  dt.Columns [0] .DataType
 

数据类型属性将设置为以下之一:

 布尔
字节
字符
日期时间
十进制
双
INT16
INT32
Int64的
为SByte
单
串
时间跨度
UINT16
UInt32的
UINT64
 

DataColumn.DataType物业MSDN参考

DataTable dt = new DataTable();  
dt.Columns.Add(new DataColumn(gridColumn1, typeof(bool)));

I was expecting the result of this line to include the info about the DataColumns Type (bool):

?dt.Columns[0].GetType()

解决方案

What you want to use is this property:

dt.Columns[0].DataType

The DataType property will set to one of the following:

Boolean
Byte
Char
DateTime
Decimal
Double
Int16
Int32
Int64
SByte
Single
String
TimeSpan
UInt16
UInt32
UInt64

DataColumn.DataType Property MSDN Reference