0

why My idatareader make error .....?

 byteSize = _reader.GetBytes(_reader.GetOrdinal(sFieldName), 0, null, 0, 0);

I want to retrive image from database here sFieldName is database column Name......it show me Specified cast is not valid. message ......what i do?work on c# window vs05....

sFieldName is a string ....it's the column name of database and column type is image My database column name is "BoardImage"

sFieldName="BoardImage"

 oBoardDetail.BoardImage =oReader.GetImage("BoardImage");

here oBoardDetail is a class object and BoardImage is a class property type Image

Shamim
  • 359
  • 4
  • 12
  • 25
  • Well, for a start, what type *is* the field? – Greg Beech May 21 '09 at 08:22
  • If you have no other way to debug, try printing _reader.GetFieldType(_reader.GetOrdinal(sFieldName)), which will give you the Type object corresponding to the column's type. Then, you can correct GetBytes to the appropriate method. – Matthew Flaschen May 21 '09 at 09:05
  • 1
    Please stop asking the same question over and over again, Shamin. If you're not getting the answer you want, update your original question with more information. – Matt Hamilton May 21 '09 at 09:58

1 Answers1

0

Most likely, the column sFieldname is not an Image or VarBinary column.

Please update the missing info on database system, table structure, select statement.

devio
  • 36,858
  • 7
  • 80
  • 143