.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; } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。