读书人

怎么判断数据类型

发布时间: 2012-04-03 12:38:19 作者: rapoo

如何判断数据类型
怎样使用循环去判断 table 中的每一列的数据是否为 byte[]

DataTable table = new DataTable();
foreach (DataColumn colSource in _myDataSet.Tables[0].Columns)
{
if (判断语句)//请教大虾
{
dtData.Columns.Add(new DataColumn(colSource.ColumnName, typeof(string)));
}

[解决办法]

if (colSource.DataType == System.Type.GetType("System.Byte"))//请教大虾
{
dtData.Columns.Add(new DataColumn(colSource.ColumnName, typeof(string)));
}
参考:http://msdn.microsoft.com/en-us/library/system.data.datacolumn.datatype.aspx
[解决办法]

C# code
        DataTable table = new DataTable();        foreach(DataColumn column in table.Columns)            if(column.DataType==typeof(byte[]))                //添加 

读书人网 >asp.net

热点推荐