Reputation: 9662
How can I write the following line:
document.Total = reader.IsDBNull(reader.GetOrdinal("Total")) == true : 0.0m ? (decimal?)reader["Total"];
The error I am getting is that cannot convert type from bool to decimal?
Upvotes: 0
Views: 377
Reputation: 6981
Just to add a shorter way to handle DBNull.Value
and DataReaders.
Consider using
document.Total = (reader["Total"] as decimal?) ?? 0.0m;
Upvotes: 1
Reputation: 36513
You accidentally flipped the ?
and :
. It should be:
document.Total = reader.IsDBNull(reader.GetOrdinal("Total")) == true ? 0.0m : (decimal?)reader["Total"];
Upvotes: 4