将空值转换为十进制值 [英] Convert null value to decimal value

查看:87
本文介绍了将空值转换为十进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据库中



LPvsMAXFMV数字(18,0)



LPvsMAXFMV为NULL



ASP.NET



 十进制 demo =  0 (零); 

decimal LPvsMAXFMV = Convert.ToDecimal(dtrow [ LPvsMAXFMV])!= null ? Convert.ToDecimal(dtrow [ LPvsMAXFMV]):demo;





这不起作用,如何解决这个

解决方案

使用 decimal.TryParse Nullable Decimal 喜欢...

  decimal  tmpvalue; 
十进制? result = decimal .TryParse(( string )dtrow [ LPvsMAXFMV], out tmpvalue)?
tmpvalue:( decimal ?) null ;


查看此链接



null和System.DBNull.Value有什么区别? [ ^ ]


之间的区别是什么?

In Database

LPvsMAXFMV numeric(18,0)

LPvsMAXFMV is NULL

ASP.NET

decimal demo=0(Zero);

decimal LPvsMAXFMV =Convert.ToDecimal(dtrow["LPvsMAXFMV"])!=null? Convert.ToDecimal(dtrow["LPvsMAXFMV"]):demo; 



This is not working, How to correct this

解决方案

Use decimal.TryParse and Nullable Decimal like...

decimal tmpvalue;
decimal? result = decimal.TryParse((string)dtrow["LPvsMAXFMV"], out tmpvalue) ?
                  tmpvalue : (decimal?)null;


Check this link

What is the difference between null and System.DBNull.Value?[^]


这篇关于将空值转换为十进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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