R
Richard Brown
I have a datareader object where I am trying to convert the fields coming
from it into my structure.
The line in question is as follows:
col.Length = (reader.IsDBNull(2) ? (short)0 : reader.GetInt16(2));
col.Length is defined as a 'short'
(BTW, this is in C# code, using the intrinsic short data type)
if the field is NULL, then there is no error, if the field is not null, I
get a "Specified Cast is Invalid"
(TypeCastException).
if I take out the (short)0 and just put in (short) then the compiler throws
an error saying that int cannot by cast to short.
Help! What is going on! The database field is 'smallint'.
I am selecting from the INFORMATION_SCHEMA.COLUMNS collection, this is
happening when trying to read the CHARACTER_MAXIMUM_LENGTH field.
from it into my structure.
The line in question is as follows:
col.Length = (reader.IsDBNull(2) ? (short)0 : reader.GetInt16(2));
col.Length is defined as a 'short'
(BTW, this is in C# code, using the intrinsic short data type)
if the field is NULL, then there is no error, if the field is not null, I
get a "Specified Cast is Invalid"
(TypeCastException).
if I take out the (short)0 and just put in (short) then the compiler throws
an error saying that int cannot by cast to short.
Help! What is going on! The database field is 'smallint'.
I am selecting from the INFORMATION_SCHEMA.COLUMNS collection, this is
happening when trying to read the CHARACTER_MAXIMUM_LENGTH field.