From: Bob L. <bo...@ta...> - 2004-03-16 00:49:52
|
Carols: I am trying to fill a stream from a blob field using a DataReader. The = code is from the .Net BLOB examples. Below is the code I am using and = the exception. Could you look at this and help me figure out what I am = doing wrong? Thanks Bob Code: private FileStream LoadFileStream ( FbDataReader aReader, out object[] = aRecipeArray ) { aRecipeArray =3D null; BinaryWriter bw =3D null; // Streams the BLOB to the FileStream = object. FileStream fs =3D null; int bufferSize =3D 100; // Size of the BLOB buffer. byte[] outbyte =3D new byte[ bufferSize ]; // The BLOB byte[] buffer to = be filled by GetBytes. long retval; // The bytes returned from = GetBytes. long startIndex =3D 0; // The starting position in = the BLOB output. try { while ( aReader.Read() )=20 { aRecipeArray =3D new object[ RecipeColCount ]; aReader.GetValues( aRecipeArray ); fs =3D new FileStream( RecipeWorkStreamPath, FileMode.OpenOrCreate, = FileAccess.Write); bw =3D new BinaryWriter( fs ); // Reset the starting byte for the new BLOB. startIndex =3D 0; // Read the bytes into outbyte[] and retain the number of bytes = returned. // exception here retval =3D aReader.GetBytes( 1, startIndex, outbyte, 0, bufferSize); Exception Code: "System.InvalidCastException: Specified cast is not valid.\r\n =20 at FirebirdSql.Data.Firebird.FbDataReader.GetBytes(Int32 i, Int64 = dataIndex, Byte[] buffer, Int32 bufferIndex, Int32 length)\r\n at = DbUtility.DBUtilityForm.LoadFileStream(FbDataReader aReader, Object[]& = aRecipeArray) in d:\\dbutility\\form1.cs:line 637" |