特定的列值必须为整数 [英] particular column values must be in integer

查看:45
本文介绍了特定的列值必须为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查dataTable中的每行值数据类型.例如ProjectId列的行值必须为整数..如何检查它

How to check the Each row values datatype in dataTable.For Example ProjectId Column''s row values are must be integer..how to check it

推荐答案

您可以检查任何类型的变量
You can check for any type of variable
string ot ="adas";
if (ot is string)
   return string;
else if (ot is int)
   return int;


u可以使用int .TryParse为此:
u can use int.TryParse for this:
foreach (DataRow dr in datatable.Rows)
{
    int temp;

    bool flag = int.TryParse(dr["ProjectId"].ToString(), out temp);

    if (flag == true)
    {
        //if success, i.e. ProjectId is int. its value will be in variable temp
    }
    else
    {
        //if failure, i.e ProjectId is not integer
    }
}


这篇关于特定的列值必须为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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