.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 ...
随机推荐
- Python开发技术详解(视频+源码+文档)
Python, 是一种面向对象.直译式计算机程序设计语言.Python语法简捷而清晰,具有丰富和强大的类库.它常被昵称为胶水语言,它能够很轻松的把用其他语言制作的各种模块(尤其是C/C++)轻松地联结 ...
- C#生成PDF
参考书籍 http://wenku.baidu.com/link?url=N2jjf_JNIuKUxkODxePvNTlZNyFQ6qsx_TPKenDqhL9ShKojw95gs38fHihXg2e ...
- SQL学习之Insert的特殊用法(插入检索出的数据,表之间的数据复制)
1.插入检索出的数据 select * from dbo.Customers_1
- English - therefore,so,hence,then,accordingly,thus用法解析
这几个词的区别大致可从以下几方面去看: 1.therefore adv.因此, 所以=for that reason=consequently常用于连接两个并列分句,其前加“and”或分号“:”.He ...
- VS2013 快捷键 VS RESHARPER 设置
一直用Resharper插件,最近发现Ctrl+E,C快捷见被Resharper的快捷功能吞掉了,折腾了几小时终于找到解决方法了,特记分享之. 采用如下步骤可以让快捷键回到vs2012的默认方式,同时 ...
- 一个JAVA代码
public class HelloJava { public static void main(String[] args) { System.out.println("这"); ...
- textarea中的空格与换行
当在一个textarea标签中键入一个回车时,实际上会插入2个符号:\n\r在javascript里, line breaks用\n表示when you pull text into Javascri ...
- 关于Python网络爬虫实战笔记③
Python网络爬虫实战笔记③如何下载韩寒博客文章 Python网络爬虫实战笔记③如何下载韩寒博客文章 target:下载全部的文章 1. 博客列表页面规则 也就是, http://blog.sina ...
- Android 程序申请权限小知识点
在Google Play 应用商店,显示至少支持设备的数量时候会用到权限数量.其他地方用处不大. Android系统提供为程序提供了权限申请,即在manifest中使用uses-permission来 ...
- Ubuntu14下LAMP环境的安装以及yaf扩展的安装
前段时间在ubuntu下安装了lamp环境,记录一下安装过程方便以后查阅. 安装lamp环境 ① 安装apache sudo apt-get install apache2 系统会弹出如图所示的提示, ...