将空值转换为十进制值 [英] Convert null value to decimal value
本文介绍了将空值转换为十进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在数据库中
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
解决方案
Usedecimal.TryParse
andNullable 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屋!
查看全文