.net DataTable 取值辅助类

DataTableCommon类主要是帮助取值

方法列表:

public static string GetCellString(DataTable dt,int row, int column)

public static string GetCellString(DataTable dt,int row, string columnName)

public static int GetCellInt(DataTable dt, int row, int column)

public static int GetCellInt(DataTable dt, int row, string columnName)

public static decimal GetCellDecimal(DataTable dt, int row, int column)

public static decimal GetCellDecimal(DataTable dt, int row,string columnName)

public class DataTableComon
    {
        public static string GetCellString(DataTable dt,int row, int column)
        {
            string strValue = string.Empty;
            try
            {
                if (dt == null || dt.Rows.Count == 0)
                    return null;
                object objValue=dt.Rows[row][column];
                if (objValue == null || Convert.IsDBNull(objValue))
                    return null;
                strValue = objValue.ToString();
            }
            catch (Exception)
            {
            }
            return strValue;
        }
        public static string GetCellString(DataTable dt, int row, string columnName)
        {
            string strValue = string.Empty;
            try
            {
                if (dt == null || dt.Rows.Count == 0)
                    return null;
                object objValue = dt.Rows[row][columnName];
                if (objValue == null || Convert.IsDBNull(objValue))
                    return null;
                strValue = objValue.ToString();
            }
            catch (Exception)
            {
            }
            return strValue;
        }
        public static int GetCellInt(DataTable dt, int row, int column)
        {
            int intValue = 0;
            try
            {
                if (dt == null || dt.Rows.Count == 0)
                    return 0;
                object objValue = dt.Rows[row][column];
                if (objValue == null || Convert.IsDBNull(objValue))
                    return 0;
                intValue = Convert.ToInt32(objValue);
            }
            catch (Exception)
            {
            }
            return intValue;
        }
        public static int GetCellInt(DataTable dt, int row, string columnName)
        {
            int intValue = 0;
            try
            {
                if (dt == null || dt.Rows.Count == 0)
                    return 0;
                object objValue = dt.Rows[row][columnName];
                if (objValue == null || Convert.IsDBNull(objValue))
                    return 0;
                intValue = Convert.ToInt32(objValue);
            }
            catch (Exception)
            {
            }
            return intValue;
        }

        public static decimal GetCellDecimal(DataTable dt, int row, int column)
        {
            decimal intValue = 0;
            try
            {
                if (dt == null || dt.Rows.Count == 0)
                    return 0;
                object objValue = dt.Rows[row][column];
                if (objValue == null || Convert.IsDBNull(objValue))
                    return 0;
                intValue = Convert.ToDecimal(objValue);
            }
            catch (Exception)
            {
            }
            return intValue;
        }
        public static decimal GetCellDecimal(DataTable dt, int row, string columnName)
        {
            decimal intValue = 0;
            try
            {
                if (dt == null || dt.Rows.Count == 0)
                    return 0;
                object objValue = dt.Rows[row][columnName];
                if (objValue == null || Convert.IsDBNull(objValue))
                    return 0;
                intValue = Convert.ToDecimal(objValue);
            }
            catch (Exception)
            {
            }
            return intValue;
        }
    }
时间: 2024-08-08 06:19:55

.net DataTable 取值辅助类的相关文章

枚举类型取值helper类

枚举类型取值: 1.根据枚举下标拿取值(默认为 0,1,2,3,4) 2.根据枚举描述拿到枚举值 3.根据枚举下标拿到枚举值(不限下标,如101开头) 调用方法 调用1:Enum.GetNames(typeof(AddAttributeType))[0];   //注:这个适用于枚举下标为默认0开始的,拿到的值为string类型的枚举值(如果下标超出会报异常) 调用 2:EnumMethodHelper.EnumToDescription("101", typeof(AddAttrib

mysql中bigint、int、mediumint、smallint 和 tinyint的取值范

mysql数据库设计,其中,对于数据性能优化,字段类型考虑很重要,搜集了些资料,整理分享出来,这篇为有关mysql整型bigint.int.mediumint.smallint 和 tinyint的语法介绍,如下:1.bigint 从 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型数据(所有数字),无符号的范围是0到 18446744073709551615.一位为 8 个字节. 2.int 一个正常大小整数.有符号

关于offsetLeft的取值

ele.offsetLeft的取值,如果ele是body的直接子元素,那么ele.offset的取值就是ele距离body左侧的距离. 但是如果ele不是body的直接子元素,中间还有其他元素,而且中间元素存在margin边距值,在相对高级的浏览器和ie6\7之间,ele.offsetLeft就会产生不同的取值. 只要ele的父元素使用了定位,不论是相对定位还是绝对定位.那么各个浏览器的ele.offsetLeft取值就会全部相同,都是现对于这个父元素左边距. 但这仅仅是对ele的父元素使用定位

php floor 取值问题

事情是这样的,在公司有客户反应会少一个进个一位数字,大概类似百度百科这样 <?php $str=41.23*5000; echo  floor($str); echo  "<br>"; echo intval($str); ?> 应该得到206150,为什么他是得到206149呢 解决办法: 可以用strval转一下 原因: 这是计算机内部问题 浮点数的计算永远都不会完全准确 例如 1/3 表示 0.333333...............后面N个3,但是计算

使用Struts框架的Java Web项目中的两个Session的区别和常见的Session取值为空的错误

我的百度知道回答,感觉这个知识很有意义,专门贴出来. 不过还有待验证的地方,就是 ActionContext.getContext().getSession("name", "Tom"); //如果在JSP中通过 EL 或者 Struts2 标签怎么显示? 以下是回答正文. 很多初学Java Web的同学因为使用 Strut2框架而分不清两个 Session的区别. 1.   JSP/Servlety有个原生的 session 对象,这是9大内置对象中的一个,书上写

js 定义像java一样的map方便取值

js 定义像java一样的map方便取值. 百度有位大神说"js对象本身就是一种Map结构",这真是一段让人欢天喜地的代码. <script> //定义一个全局map var map = {}; var key0 = '0'; var key1 = '1'; map[key0] = '0-真实报文'; map[key1] = '1-虚拟报文'; //row 获取这行的值 ,index 获取索引值 function testJsMap(key){ //如果遍历map for(

17 Java语言基础long与float的取值范围谁大谁小

结论 float的取值范围比long大 验证 1 public class Test1_DataTypeConversion { 2 3 public static void main(String[] args) { 4 5 float f = 1.3f; 6 long l = 34; 7 // l = f; 8 // System.out.println(l); 9 //Type mismatch: cannot convert from float to long 10 f = l; 11

添加Properties取值和枚举取值

<!--配置文件--><property name="ppp"> <props> <prop key="11">hello</prop> <prop key="22">bye</prop> </props> </property> </bean> 取值App1类代码: System.out.println("****通

jquery操作select(取值,设置选中)

最近工作中总出现select 和 option问题,整理一下,内容大部分源于网络资料 一.基础取值问题 例如<select class="selector"></select> 1.设置value为pxx的项选中 $(".selector").val("pxx"); 2.设置text为pxx的项选中 $(".selector").find("option[text='pxx']").