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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…