I need to round and print a price like below, but this does not handle null values.
How can I handle null values on one line of code?
DBRSet is an SQLDataReader and the price is money type in SQL.
<%= Math.Round(DBRSet("price"))%>
I have about 200 .aspx pages of this so I could also use some tips on how to change these in an easy way? Can I do a search and replace with a reg-exp or something like that?
You have to handle the
DbNullcase explicitly, for example:This is unwieldy, so it makes sense to have a helper method something like this somewhere:
Which would allow
Of course finding and changing all such code to use the helper method would be… unpleasant. I would do it by searching throughout the project (maybe in smaller chunks of the project) for something indicative (maybe
Math.Round?) and review it manually before replacing.