From: David V <dav...@ho...> - 2002-12-30 07:44:43
|
Hi, Thanks for the fix regarding inserting Blobs, but now the obvious next question - how to read Blobs from a table. The following code: command.CommandText = "SELECT description FROM TESTBLOB WHERE ITEMID = " + aId; FileStream fs; BinaryWriter bw; FileStream object. int bufferSize = 100; byte[] outbyte = new byte[bufferSize]; long retval; long startIndex = 0; // Open the connection and read data into the DataReader. FbDataReader myReader = command.ExecuteReader(CommandBehavior.SequentialAccess); while (myReader.Read()) { // Create a file to hold the output. fs = new FileStream(@"C:\Development\Temp\blob.xml", FileMode.OpenOrCreate, FileAccess.Write); bw = new BinaryWriter(fs); // Reset the starting byte for the new BLOB. startIndex = 0; // Read the bytes into outbyte[] retval = myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize); // Continue reading and writing while there are bytes while (retval == bufferSize) { bw.Write(outbyte); bw.Flush(); startIndex+= bufferSize; retval = myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize); } } Throws the exception: [2568] ERROR application-log - Exception: System.NotSupportedException: GetBytes not supported. at FirebirdSql.Data.Firebird.FbResultset.GetBytes(Int32 i, Int64 fieldOffset, Byte[] buffer, Int32 bufferOffset, Int32 length) at FirebirdSql.Data.Firebird.FbDataReader.GetBytes(Int32 i, Int64 fieldOffset, Byte[] buffer, Int32 bufferOffset, Int32 length) And the code: command.CommandText = "SELECT itemId, description FROM TESTBLOB WHERE ITEMID = " + aId; DataSet metadataDS = new DataSet(); FbDataAdapter adapter = new FbDataAdapter(command); adapter.Fill(metadataDS, "TESTBLOB"); string metadata = metadataDS.GetXml(); Throws the exception: Exception: FirebirdSql.Data.INGDS.GDSException Message: Exception of type FirebirdSql.Data.INGDS.GDSException was thrown. Source: FirebirdProvider at FirebirdSql.Data.Firebird.Blob.Close(isc_blob_handle_impl blob_handle) at FirebirdSql.Data.Firebird.FbBlob.Read() at FirebirdSql.Data.Firebird.FbResultset.GetBlobData(Int64 blob_id) at FirebirdSql.Data.Firebird.FbResultset.GetValue(Int32 i) at FirebirdSql.Data.Firebird.FbDataReader.GetValue(Int32 i) at FirebirdSql.Data.Firebird.FbDataReader.GetValues(Object[] values) at System.Data.Common.SchemaMapping.LoadDataRow(Boolean clearDataValues, Boolean acceptChanges) at System.Data.Common.DbDataAdapter.FillLoadDataRow(SchemaMapping mapping) at System.Data.Common.DbDataAdapter.FillFromReader(Object data, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) at System.Data.Common.DbDataAdapter.Fill(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) Any ideas of whats wrong? _________________________________________________________________ MSN 8 with e-mail virus protection service: 3 months FREE*. http://join.msn.com/?page=features/virus&xAPID=42&PS=47575&PI=7324&DI=7474&SU= http://www.hotmail.msn.com/cgi-bin/getmsg&HL=1216hotmailtaglines_eliminateviruses_3mf |