获取数据表列数据类型 [英] Get a DataTable Columns DataType

查看:260
本文介绍了获取数据表列数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

 ?dt.Columns [0] .GetType()
 

解决方案

您想用什么这个属性是:

  dt.Columns [0] .DataType
 

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

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

<一个href="http://msdn.microsoft.com/en-us/library/system.data.datacolumn.datatype.aspx">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

这篇关于获取数据表列数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆