1

我正在使用OleDbDataReader rdr将 BLOB 形式的“评论”字段(sub_type 1 段大小 80)读取到来自 Interbase DB 的字符串中,并且我不断收到异常。有什么建议么?

尝试#1

ls_Chap_Comments.Add((rdr["Comments"]).ToString());

InvalidCastException:由于符号不匹配或数据溢出以外的原因,无法转换数据值。例如,数据存储中的数据已损坏,但该行仍可检索。”

尝试#2

byte[] b = new byte[100];
b = (byte[])rdr["Comments"];
string s = System.Text.ASCIIEncoding.ASCII.GetString(b);

InvalidCastException:无法将类型的对象转换System.String为类型System.Byte[]

尝试#3

// 17 is the BLOB column zero-based location for "Comments"
retval = rdr.GetBytes(17, startIndex, outbyte, 0, bufferSize);    

InvalidCastException:无法将类型的对象转换System.String为类型System.Byte[]

任何建议将不胜感激!

4

2 回答 2

0

你应该打电话

rdr.IsDBNull(rdr.GetOrdinal("Comments"))

在尝试读取值之前。

于 2012-11-25T04:45:19.690 回答
0

我一直在寻找这个问题的答案,但这并不像看起来那么困难。将值作为对象类型检索并将其转换为字符串(假设 blob 包含字符串)。

string commentsValue = (string)rdr.GetValue(17);
于 2017-03-27T11:40:02.280 回答