.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 ...
随机推荐
- 米兰站热卖:奢侈品电商困局已破?-搜狐IT
米兰站热卖:奢侈品电商困局已破?-搜狐IT 米兰站热卖:奢侈品电商困局已破?
- i美股投资研报--Michael Kors(IPO版) _Michael Kors(KORS) _i美股
i美股投资研报--Michael Kors(IPO版) _Michael Kors(KORS) _i美股 i美股投资研报--Michael Kors(IPO版)
- CSS3立体文字最佳实践
前端开发whqet,csdn,王海庆,whqet,前端开发专家 上一篇的<纯CSS3文字效果推荐>文章里面推荐了8款纯css实现的文字效果,当中3d文字效果最为流行,限于篇幅只展示了其3D ...
- 引入css ,使用@import和link的方式
我们也经常听到有人说要使用link来引入CSS更好,但是你知道为什么吗? 继续往下看 linklink就是把外部CSS与网页连接起来. @importimport文字上与link的区别就是它可以把在一 ...
- JavaScript引用类型之Array数组的concat()和push()方法的区别
在javascript中,我们一般都只用push向数组的尾部插入新元素的,但是其实在javascript中还有另外一个方法和push一样,也是向数组尾部插入新元素的,但是他们之间却存在着一定的区别,当 ...
- shell命令基础
1.修改密码 使用 passwd 命令修改密码. 该命令如果在 root 用户下执行,则修改的是 root 用户的密码. 2.获取帮助 使用 ls --help 命令获取帮助. [zhanghuiju ...
- 用for循环遍历DataTable中的数据
for (int i = 0; i < dataTable.Rows.Count; i++) { for (int j = 0; j < dataTable.Columns.Count; ...
- SQL server与Oracle触发器的创建与使用
SQL Server 1创建触发器 GO BEGIN IF (object_id('WMY', 'tr') is not null) DROP trigger WMY END; GO CREATE T ...
- ul li 好友列表
<div class="col-md-4 mt"> <div class="friend-list"> <h4 class=&qu ...
- WinSock网络编程基础(1)
记录学习windows网络编程过程中遇到的问题和相关笔记 基本概念: Socket: socket起源于UNIX,Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口.基于&qu ...