This might seem an easy question for some, but I am struggling with it.
I am trying to use SQLDataReader.GetFieldType to check if a certain field is an Image field. Lets assume the first field of the result set is an Image field, if I do:
reader.GetFieldType(0).ToString;
I get System.Byte[] But is this the correct way to check for it? I really don’t like:
if (reader.GetFieldType(0).ToString="System.Byte[]")
Is there a better way?
Thanks,
AJ
You could always shorten it a bit:
Unfortunately there’s no direct mapping from an image field in SQL Server to a .NET CLR type…which is why you get a byte array.
You might want to add further checking to make sure that the byte array being returned is actually an image (byte arrays are used for
image,binary,varbinary, androwversioncolumns as well).You can check the type mappings at:
MSDN – Mapping CLR Parameter Data