Converting Byte[] to String - Interbase to C# - InvalidCastException
- by NorthernOutpost
I'm using OleDbDataReader rdr to read a "Comments" field in BLOB form (sub_type 1 segment size 80) into a string from an Interbase DB, and I keep getting exceptions. Any suggestions?
Attempt #1
ls_Chap_Comments.Add((rdr["Comments"]).ToString());
InvalidCastException: The data value could not be converted for reasons other than sign mismatch or data overflow. For example, the data was corrupted in the data store but the row was still retrievable."
Attempt #2
byte[] b = new byte[100];
b = (byte[])rdr["Comments"];
string s = System.Text.ASCIIEncoding.ASCII.GetString(b);
InvalidCastException: Unable to cast object of type System.String to type System.Byte[]
Attempt #3
// 17 is the BLOB column zero-based location for "Comments"
retval = rdr.GetBytes(17, startIndex, outbyte, 0, bufferSize);
InvalidCastException: Unable to cast object of type System.String to type System.Byte[].
Any suggestions would be really appreciated!