在网上找一段代码,改了一下,之后,会报这个错误啊。
System.InvalidCastException: 指定的转换无效。源错误: 
行 162: objBw = new BinaryWriter(objFs);
行 163: startIndex = 0;
行 164: retval = objDr.GetBytes(8, startIndex, outByte, 0, bufferSize);这是为什么啊?
 
代码如下:
Conn();
scom = new OracleCommand();
scom.Connection=scon;
scom.CommandText = "....";
FileStream objFs;
BinaryWriter objBw;
int bufferSize = 260;
byte [] outByte = new byte[bufferSize];
long retval;
long startIndex = 0;
string fileName = "";

OracleDataReader objDr = scom.ExecuteReader(CommandBehavior.CloseConnection);
objDr.Read();
fileName = objDr["NAME"].ToString();
objFs = new FileStream(Path.GetTempPath()+fileName, FileMode.OpenOrCreate,FileAccess.Write);
objBw = new BinaryWriter(objFs);
startIndex = 0;
retval = objDr.GetBytes(8, startIndex, outByte, 0, bufferSize);
 while ( retval == bufferSize)
{
  objBw.Write(outByte);
  objBw.Flush();
  startIndex += bufferSize;
  retval = objDr.GetBytes(8, startIndex, outByte, 0, bufferSize);
}
objBw.Write(outByte, 0, (int)retval -1);
objBw.Flush();
objBw.Close();
objFs.Close();
objDr.Close();
scon.Close();