If I have code similar to the following:
while(myDataReader.Read())
{
myObject.intVal = Convert.ToInt32(myDataReader["mycolumn"] ?? 0);
}
It throws the error:
Object cannot be cast from DBNull to other types.
defining intVal as a nullable int is not an option. Is there a way for me to do the above?
Can you use an extension method? (written off the top of my head)
You’d use it like: