如何检查数据表是否包含任何匹配的行? [英] How to check whether datatable contains any matched rows?

查看:60
本文介绍了如何检查数据表是否包含任何匹配的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用计算汇总具有条件的数据表.有时,数据表中没有符合我条件的行,所以我在Compute上遇到异常无法将对象从DBNull强制转换为其他类型.

I am using Compute for summing up a datatable which has a condition. Sometimes, there are no rows inside the datatable matching my criteria so I get an exception on Compute Object cannot be cast from DBNull to other types.

有没有一种方法可以检查/过滤数据表以查看其是否具有所需的行,如果只有,则应用Compute.请指教.

Is there a way to check/filter the datatable to see if it has the desired rows, if yes only then I apply Compute. Please advice.

total = Convert.ToDecimal(CompTab.Compute("SUM(Share)", "IsRep=0"));

推荐答案

尝试一下

object objCompute=CompTab.Compute("SUM(Share)", "IsRep=0");
if(objCompute!=DBNull.Value)
{
total = Convert.ToDecimal(objCompute);
}

这篇关于如何检查数据表是否包含任何匹配的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆