index > .NET Framework Data Access and Storage > Nobody can answer this question!

Nobody can answer this question!

Big Smile
Following sample C# codes are from MSDN, to create a bmp file from an BLOB column in Microsoft Access DB, which was also imported from another bmp file.

=============================================================

DB_Conn_String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\Inetpub\\wwwroot\\ruiwen.mdb";

ImgConn = new OleDbConnection( DB_Conn_String );

ImgDataAdapter = new OleDbDataAdapter();


FileStream fs; // Writes the BLOB to a file (*.bmp).

BinaryWriter bw; // Streams the BLOB to the FileStream object.

int bufferSize = 100; // Size of the BLOB buffer.

byte[] outbyte = new byte[bufferSize]; // The BLOB byte[] buffer to be filled by GetBytes.

long retval; // The bytes returned from GetBytes.

long startIndex = 0; // The starting position in the BLOB output.

int img_id = 0; // The image #.

// Open the connection and read data into the DataReader.

OleDbCommand cmd;

DataRow my_row;

// Create the SelectCommand.

cmd = new OleDbCommand( "SELECT * FROM rw_obj", ImgConn );

ImgConn.Open();

OleDbDataReader myReader = cmd.ExecuteReader( CommandBehavior.SequentialAccess );

while( myReader.Read() )

{

img_id++;

// Create a file to hold the output.

fs = new FileStream( "c:\\rw" + img_id + ".bmp", FileMode.OpenOrCreate, FileAccess.Write );

bw = new BinaryWriter( fs );

// Reset the starting byte for the new BLOB.

startIndex = 0;

// Read the bytes into outbyte[] and retain the number of bytes returned.

retval = myReader.GetBytes( 2, startIndex, outbyte, 0, bufferSize );

// Continue reading and writing while there are bytes beyond the size of the buffer.

while (retval == bufferSize)

{

bw.Write(outbyte);

bw.Flush();

// Reposition the start index to the end of the last buffer and fill the buffer.

startIndex += bufferSize;

retval = myReader.GetBytes( 2, startIndex, outbyte, 0, bufferSize );

}

// Write the remaining buffer.

bw.Write( outbyte, 0, ( int )retval - 1 );

bw.Flush();

// Close the output file.

bw.Close();

fs.Close();

}

// Close the reader and the connection.

myReader.Close();

ImgConn.Close();

==============================================================

However, the program is very unsuccessful. Although the new bmp file was generated, but it is inaccessible to Paint Brush and other image tools, and even the size was different from the original bmp file.

If there is any solution, whether it is also applicable to jpg and other image formats?

Big Smile

moonriver

Hi moonriver,

BLOB (Binary Large Object) data type non exist in MS Office Access. That is OLE. I'm sorry. The BLOB's data type are Oracle database.

Good Coding!

Javier Luna
http://guydotnetxmlwebservices.blogspot.com/




Indigo: Ports, Messages, Channels and more...
Javier Luna

BLOB is also used as a generic term.

I have tried your code above and it works fine. The only changes I made are that I set the buffer size to the size of my image and I only write the remaining buffer if there is something in it.

My guess is either your buffer size is too small or as Javier has hinted at the image in the access image is actually an OLE object. You will see in all the MS examples where they use the North wind database that they seek over the OLE header on the image fields. I think the header is 78 bytes.

Dion
Dion Brown
reply 3

You can use google to search for other answers

 

More Articles

• Walkthrough: Creating a Master-Detail Windows Form
• Saving a Blob file into SQL Server with Visual Studio .Net 2005
• DataSet Vs DataReader????
• transaction problem
• how to show rows in dataset when filling it? as wizzard do.
• Framework Versions
• Com Exception is unhandeled while executing ExecuteReader
• Connection Pooling randomly throwing COM exceptions
• Update SQL database...Please help
• OCI-22053: overflow error caused when retreiving valid data inser...
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Selecting / Update records - Concurrancy
• Dynamically remove textbox
• Determination of Business Logic location
• DateTime Conversions
• Table Adapter, set foreign key fields on
• Help: UInt32 vs Int32 as foreign and pri
• Automatic Designer Replacement of 'local
• Retrieving @@Identity from Access databa
• Update Excel Data
• Issues with updating Access DataSource
• DataTable.Load() Generates InvalidOperat
• How to invoke a .asp file or .aspx file
• interacting applications
• database diagram node in server explorer
• Embarrassing Problem with inserting reco

Hot Articles

• difficulty accessing Excel spreadsheet v
• bool true, false values with SqlData
• Insert Data from DataReader into a TextBox
• DataTable select problem!!!!!!!!!!!!!
• Default Values with a DataSet and SQL Se
• can we call myDataSet.AcceptChanges befo
• Should I reinstall?
• If for my web app, I set max connection
• How to retrieve value from UDT column wr
• Why doesn't my C# form show the contents
• URGENT Problem with Greek Character from
• Database update works as console app, fa
• Problem Enumerating Sql Server Using Sys
• OdbcConnection problem
• Import data from Excel

Recommend Articles

• System.NullReferenceException: Using Dat
• Generating sql query using C# code
• informix: exist a wizard to create datas
• DataSet Merging
• Query a View
• [OTP]virus burst then hpiz350-internal e
• Best Practices question.
• OracleClient DataAdapter
• help: I need to view all the tables in a
• Performance question with DataReader
• ADO Datareader Bug? Datareader creates a
• XML Schema Help with FIX 4.4
• An error has occurred while establishing
• What is the maximum number of tables in
• catcha sqlexception and column