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 =newbyte[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

Report
[5541 byte] By [moonriver] at [2007-12-16]
# 1

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/

JavierLuna at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 2

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
DionBrown at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified