I’m getting the error in the title “Conversion from type ‘DBNull’ to type ‘Decimal’ is not valid.” from this line of code
_event.TotalDollars = IIf((dr("TotalDollars") Is DBNull.Value), "$0", CType(dr("TotalDollars"), Decimal).ToString("c"))
_event.TotalDollars is a string
Why is the third part of IIF statement ever getting evaluated? The whole point of this IIF is so that DBNull values are not attempted to be converted into Decimals.
Two problems:
IIFevaluates both the True and False operations before returning.Depending on which version of VS you have you could just use
If(condition,true,false)instead (which doesn’t)Also, you’re probably better to use
IsDbNull(condition)to do the test.