对象不能从dbnull传递给其他类型? [英] object can't be pass from dbnull to other types?

查看:42
本文介绍了对象不能从dbnull传递给其他类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是抛出错误的代码:如何解决它。







Here is the code that is throwing the error : how to resolve it.



var patActivity = _ngDbContext.PATIENTACTIVITies.Where(x => x.CompanyID == RXDF.Constants.CompanyId

                   && x.ClientID == DataFeed.SPPeReferralOutbound.Ids.ClientId
                   && x.ProgramID == DataFeed.SPPeReferralOutbound.Ids.ProgramId
                   && x.PatientID == Convert.ToDecimal(row["CimplicityPatientCaseID"])
                   && x.CaseID == Convert.ToDecimal(row["CaseID"])
                   && x.PatActID == Convert.ToDecimal(row["PatActID"])).SingleOrDefault();







在此先感谢。




Thanks In Advance.

推荐答案

很难说这么少的信息,但猜测是其中一列在变量 row 中设置为null。



更改为

Difficult to say with so little information, but a guess is that one of the columns in the variable row is set to null.

Change from
Convert.ToDecimal(row["CimplicityPatientCaseID"])



to


to

DBNull.Value.Equals(row["CimplicityPatientCaseID"]) ? 0 : Convert.ToDecimal(row["CimplicityPatientCaseID"])





并对其他列执行相同操作, CaseID PatActID


似乎有些列数据为空。所以为了避免使用如下代码:

It seems some of column data is null. So in order to avoid use code like below:
x.PatientID == (Convert.IsDBNull(row["CimplicityPatientCaseID"])? 0 : Convert.ToDecimal(row["CimplicityPatientCaseID"]));



注意:做同样的事情其他两列CaseID和PatActID


Note: Do the same for other two columns CaseID and PatActID


这篇关于对象不能从dbnull传递给其他类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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