有没有办法找到数据表中任何列的数据类型? [英] Is there any way to findout the datatype of any column in a datatable?
本文介绍了有没有办法找到数据表中任何列的数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个有一个数据表的数据集。我想知道每个列名的数据类型,如是数字还是varchar(字符串)?
有没有办法识别列的数据类型?
Suppose, I have a dataset which has one datatable. I want to know the datatype of every columnname like Is it numeric or varchar (string)?
Is there any way to identify the datatype of a column ?
推荐答案
DataSet-> Tables-> DataTable-> Columns-> DataColum-> DataType
http://msdn.microsoft.com/en-us/library/system .data.datacolumn.datatype.aspx [ ^ ]
DataSet->Tables->DataTable->Columns->DataColum->DataType
http://msdn.microsoft.com/en-us/library/system.data.datacolumn.datatype.aspx[^]
编辑:评论说它不起作用。只是想帮忙。
你可以使用这样的东西
as comments say it doesn't work. just wanted to help.
You can use something like this
foreach (DataRow row in dataSet2.Tables[0].Rows)
{
foreach (DataColumn col in dataSet2.Tables[0].Columns)
{
if(row[col].GetType() == typeof(int)){
row[col] = 0;
}
if (row[col].GetType() == typeof(string))
{
row[col] = "no data";
}
}
}
这篇关于有没有办法找到数据表中任何列的数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文