Help! TypeCastConversion?

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.
 
R

Richard Brown

Never mind, I got it....
The documentation for SQL2000 (Online Books) and the definition of the
actual INFORMATION_SCHEMA views is wrong!

The column is question is supposed to be reported as a smallint, howevere,
in the view, there is an explicit conversion to int.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top