Is there a better/cleaner way to do this?
int stockvalue = 0; if (!Convert.IsDBNull(reader["StockValue"])) stockvalue = (int)reader["StockValue"];
The shortest (IMHO) is:
int stockvalue = (reader["StockValue"] as int?) ?? 0;
Explanation:
2.1m questions
2.1m answers
60 comments
57.0k users