.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 == )
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 == )
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 = ;
try
{
if (dt == null || dt.Rows.Count == )
return ;
object objValue = dt.Rows[row][column];
if (objValue == null || Convert.IsDBNull(objValue))
return ;
intValue = Convert.ToInt32(objValue);
}
catch (Exception)
{
}
return intValue;
}
public static int GetCellInt(DataTable dt, int row, string columnName)
{
int intValue = ;
try
{
if (dt == null || dt.Rows.Count == )
return ;
object objValue = dt.Rows[row][columnName];
if (objValue == null || Convert.IsDBNull(objValue))
return ;
intValue = Convert.ToInt32(objValue);
}
catch (Exception)
{
}
return intValue;
} public static decimal GetCellDecimal(DataTable dt, int row, int column)
{
decimal intValue = ;
try
{
if (dt == null || dt.Rows.Count == )
return ;
object objValue = dt.Rows[row][column];
if (objValue == null || Convert.IsDBNull(objValue))
return ;
intValue = Convert.ToDecimal(objValue);
}
catch (Exception)
{
}
return intValue;
}
public static decimal GetCellDecimal(DataTable dt, int row, string columnName)
{
decimal intValue = ;
try
{
if (dt == null || dt.Rows.Count == )
return ;
object objValue = dt.Rows[row][columnName];
if (objValue == null || Convert.IsDBNull(objValue))
return ;
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 = ;
try
{
if (dataRow == null )
return ;
object objValue = dataRow[column];
if (objValue == null || Convert.IsDBNull(objValue))
return ;
intValue = Convert.ToInt32(objValue);
}
catch (Exception)
{
}
return intValue;
}
public static int GetCellInt(DataRow dataRow, string columnName)
{
int intValue = ;
try
{
if (dataRow == null)
return ;
object objValue = dataRow[columnName];
if (objValue == null || Convert.IsDBNull(objValue))
return ;
intValue = Convert.ToInt32(objValue);
}
catch (Exception)
{
}
return intValue;
} public static decimal GetCellDecimal(DataRow dataRow,int column)
{
decimal intValue = ;
try
{
if (dataRow == null )
return ;
object objValue = dataRow[column];
if (objValue == null || Convert.IsDBNull(objValue))
return ;
intValue = Convert.ToDecimal(objValue);
}
catch (Exception)
{
}
return intValue;
}
public static decimal GetCellDecimal(DataRow dataRow, string columnName)
{
decimal intValue = ;
try
{
if (dataRow == null)
return ;
object objValue = dataRow[columnName];
if (objValue == null || Convert.IsDBNull(objValue))
return ;
intValue = Convert.ToDecimal(objValue);
}
catch (Exception)
{
}
return intValue;
} #endregion
}
.net DataTable 取值辅助类的更多相关文章
- C#读取Excel,DataTable取值为空的解决办法
连接字符串这么些就行了 string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + opnFileName ...
- SELECT INTO和INSERT INTO SELECT的区别 类似aaa?a=1&b=2&c=3&d=4,如何将问号以后的数据变为键值对 C# 获取一定区间的随即数 0、1两个值除随机数以外的取值方法(0、1两个值被取值的概率相等) C# MD5 加密,解密 C#中DataTable删除多条数据
SELECT INTO和INSERT INTO SELECT的区别 数据库中的数据复制备份 SELECT INTO: 形式: SELECT value1,value2,value3 INTO Ta ...
- js从后台无法取值问题
前台代码 <script type="text/javascript"> $(function () { var chart; $(document).ready(fu ...
- DataTbale取值
有一个DataTable数据 //创建DataTable对象 DataTable dt = new DataTable("Table_AX"); //为DataTable创建列 / ...
- QTP自动化测试-按行取值(win10下输入?问题)-笔记20181119
在win10下运行qtp10 所有输入汉字都会为?,在win7下可以.查询了百度.bingo没有解决问题.当前的解决办法 ,在脚本中使用DataTable取数据值,添加2行记录,一行使用汉字,一行使用 ...
- 如何解决流程开发中SheetRadioButtonList页面取值问题
分享一个常见的取值问题. 应用场景: SheetRadioButtonList控件,点击其中一项执行事件操作.如果是页面加载的情况下,值就无法取到. 具体原因如下: 我给SheetRadioButto ...
- jQuery radio的取值与赋值
取值: $("input[name='radioName']:checked").val(); 赋值: $("input[name='radioName'][value= ...
- python通过函数改变变量取值
严格讲应该是"通过函数调用,改变引用对象".python中,要区分"变量名"和"对象" 如果是类的对象,是引用类型的,那么可以通过函数调用, ...
- jsf初学selectOneMenu 绑定与取值
jsf 的selectOneMenu 最后生成的<select>标签.这里涉及到一个binding 起初一直不知道是干嘛的,后来参考了其他文章.就相当于在asp.net 中如:<as ...
随机推荐
- 君子性非异也,善假于物也 - Threejs 引入TrackballControls 查看场景
君子性非异也,善假于物也 - Threejs 引入TrackballControls 查看场景 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循" ...
- Android SQLite 事务处理
应用程序初始化时需要批量的向sqlite中插入大量数据,单独的使用for+Insert方法导致应用响应缓慢,因为 sqlite插入数据的时候默认一条语句就是一个事务,有多少条数据就有多少次磁盘操作.我 ...
- Lambda表达式图解
internal delegate int MyDel(int x); public class Lambda { ; };//匿名方法 ; };//Lambda表达式 ; };//Lambda表达式 ...
- 动态加载 js
要实现动态加载JS脚本有4种方法: 1.直接document.write <script language="javascript"> document.write(& ...
- Java和JavaScript的时间互传
原创文章,转载请注明:Java和JavaScript的时间互传 By Lucio.Yang 1.从JavaScript到Java JavaScript: function query(){ var s ...
- 利用merge存储引擎来实现分表
我觉得这种方法比较适合,那些没有事先考虑,而已经出现了得,数据查询慢的情况.这个时候如果要把已有的大数据量表分开比较痛苦,最痛苦的事就是改代码,因为程序里面的sql语句已经写好了,现在一张表要分成几十 ...
- 关于XPath的基本语法
关于XPath基础语法 关于XPath基础语法 更详细的请看: XPath语法 XPath 使用路径表达式来选取 XML 文档中的节点或节点集.节点是通过沿着路径 (path) 或者步 (steps) ...
- Javascript类型检测
原地址 http://www.cnblogs.com/fool/archive/2010/10/07/javascrpt.html 开门见山,我们先来看一下代码: var is = function ...
- java面向对象之 类和对象
OOP:Object Oriented Programming(面向对象编程) 面向对象: 1:将复杂的事情简单化. 2:面向对象将以前的过程中的执行者,变成了指挥者. 3:面向对象这种思想是符合现在 ...
- Open开发平台,认证,授权,计费
1.申请appid和appkeyhttp://wiki.connect.qq.com/%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C_oauth2-0 appid:应用的唯一 ...