首页 > Web开发 > 详细

.net DataTable 取值辅助类

时间:2015-02-25 16:53:51      阅读:415      评论:0      收藏:0      [点我收藏+]

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;
        }
    }

 

.net DataTable 取值辅助类

原文:http://www.cnblogs.com/Dylanblogs/p/4299782.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!