且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将空值转换为十进制值

更新时间:2023-02-14 20:34:09

使用 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?[^]