retrieving a byte array from a LONG RAW from oracle db

安稳与你 提交于 2019-12-11 04:08:24

问题


I am trying to pull data from a long raw field in an oracle 11g database. However I keep getting "specified cast is not valid" when I try:

cmd.InitialLONGFetchSize = 1000000;
cmd.AddRowid = true;
byte[] PicTempArray = new Byte[1024];
Oracle.DataAccess.Client.OracleDataReader Reader = cmd.ExecuteReader();

int i = 0;
while (Reader.Read())
{
   try
      {
      PicTempArray[i] = Reader.GetByte(0);
      }
   catch
      {
      }
   i++;
}

I wouldnt be surprised if I was doing a few things wrong. If you didnt guess the LONG RAW is holding some image data. Any advice is appreciated.


回答1:


GetByte is used to retrieve a single byte from a numeric column.

You want GetBytes instead. You should probably also read the documentation for "Obtaining LONG and LONG RAW Data".

(As an aside, I hope you don't really have an empty catch block - and your code would be more idiomatic if you used camelCase for your local variable names, and outdented the braces for the try and catch blocks, as they are for the while block.)



来源:https://stackoverflow.com/questions/8014913/retrieving-a-byte-array-from-a-long-raw-from-oracle-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!