无法隐式转换类型'小数?为“十进制”。 [英] Cannot implicitly convert type 'decimal?' to 'decimal'.

查看:142
本文介绍了无法隐式转换类型'小数?为“十进制”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SDR是我SqlDataReader的,我想检查curPrice值是十进制类型为null。

sdr is my sqldatareader and I want to check that the curPrice value which is of type decimal is null.

inrec.curPrice = sdr.IsDBNull(7)? (十进制?)空:sdr.GetDecimal(7);

这是错误消息我得到:

无法隐式转换类型'小数?到小数点。一个明确的
股转换存在(是否缺少强制转换?)

Cannot implicitly convert type 'decimal?' to 'decimal'. An explicit conversion exists (are you missing a cast?)

我要去哪里错了,请有人告诉我。

Where am I going wrong, please someone tell me.

推荐答案

无论是转换 curPrice 可空,或使用.Value属性可空类型。

either convert curPrice to nullable, or use .Value property of nullable types.

如果 curPrice 是一个类的属性,然后

If curPrice is a property of a class then

public decimal? curPrice
{
   get;
   set;
}

这篇关于无法隐式转换类型'小数?为“十进制”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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