zoukankan      html  css  js  c++  java
  • .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
        {
            #region DataTable 取值
            
           
            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 (dataRow == null || dataRow.Rows.Count == 0)
                        return null;
                    object objValue = dataRow.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;
            }
    
            #endregion
    
    
            #region DataRow 取值
    
           
            public static string GetCellString(DataRow dataRow, int column)
            {
                string strValue = string.Empty;
                try
                {
                    if (dataRow == null)
                        return null;
                    object objValue = dataRow[column];
                    if (objValue == null || Convert.IsDBNull(objValue))
                        return null;
                    strValue = objValue.ToString();
                }
                catch (Exception)
                {
                }
                return strValue;
            }
            public static string GetCellString(DataRow dataRow,string columnName)
            {
                string strValue = string.Empty;
                try
                {
                    if (dataRow == null)
                        return null;
                    object objValue = dataRow[columnName];
                    if (objValue == null || Convert.IsDBNull(objValue))
                        return null;
                    strValue = objValue.ToString();
                }
                catch (Exception)
                {
                }
                return strValue;
            }
            public static int GetCellInt(DataRow dataRow, int column)
            {
                int intValue = 0;
                try
                {
                    if (dataRow == null )
                        return 0;
                    object objValue = dataRow[column];
                    if (objValue == null || Convert.IsDBNull(objValue))
                        return 0;
                    intValue = Convert.ToInt32(objValue);
                }
                catch (Exception)
                {
                }
                return intValue;
            }
            public static int GetCellInt(DataRow dataRow, string columnName)
            {
                int intValue = 0;
                try
                {
                    if (dataRow == null)
                        return 0;
                    object objValue = dataRow[columnName];
                    if (objValue == null || Convert.IsDBNull(objValue))
                        return 0;
                    intValue = Convert.ToInt32(objValue);
                }
                catch (Exception)
                {
                }
                return intValue;
            }
    
            public static decimal GetCellDecimal(DataRow dataRow,int column)
            {
                decimal intValue = 0;
                try
                {
                    if (dataRow == null )
                        return 0;
                    object objValue = dataRow[column];
                    if (objValue == null || Convert.IsDBNull(objValue))
                        return 0;
                    intValue = Convert.ToDecimal(objValue);
                }
                catch (Exception)
                {
                }
                return intValue;
            }
            public static decimal GetCellDecimal(DataRow dataRow, string columnName)
            {
                decimal intValue = 0;
                try
                {
                    if (dataRow == null)
                        return 0;
                    object objValue = dataRow[columnName];
                    if (objValue == null || Convert.IsDBNull(objValue))
                        return 0;
                    intValue = Convert.ToDecimal(objValue);
                }
                catch (Exception)
                {
                }
                return intValue;
            }
    
            #endregion
        }
  • 相关阅读:
    如何将latex格式转换成word? Lei
    SEWM2012会议报告总结 Lei
    matlab图片到word的过程 Lei
    日记——有点郁闷的一天
    牛博国际开放了,等了一个月才能看牛博。
    做什么事都没有兴趣呢,怎么这么低调呢?
    读UML书
    firefox弹出窗口关闭时执行代码刷新父窗口
    终于关注了一下传说中的小强,firebug
    MOSS Export Site Column/Site Content Type
  • 原文地址:https://www.cnblogs.com/Dylanblogs/p/4299782.html
Copyright © 2011-2022 走看看