Why does SqlDataReader throw an exception when converting 0 to integer?
?dataReader(3) 0 {Short} Short: 0 ?dataReader.GetInt16(3) 0 ?dataReader.GetInt32(
It isn't a convert - it is a cast. The same as:
short x = 0; object y = x; int z = (int)y; // BOOM! InvalidCastException Specified cast is not valid.
In both cases, a short is not an int.
short
int
If unsure of the type, you might try:
int i = Convert.ToInt32(dataReader.GetValue(3));