Is there a way to handle a DataColumn returning DBNull in a single line statement?
Posted on 2014-03-24
I have a table returning a column defined at decimal(18,2). This column is allowed to return a DBNull. I am trying to eloquently handle the value in this column as I am using it just once in a method as part of an equation. This scenario is repeated for about 15 more columns returned in this table. Each column is capable of returning as DBNull and I need to be able to use (or convert for use) the DBNull as a decimal.
decimal.Parse(ds.Tables.Rows["MyNullableColumn"].ToString()) will throw an exception when the data in the column is null.