Link to home
Create AccountLog in
Avatar of cyberE-gor
cyberE-gor

asked on

How do I retrieve Ole Object (jpg file) from MSAccess 2003 using C#?

I can retrieve an OLE Object from Northwind database and change it to a c# Bitmap object.
I used an offset of 78 when reading the byte array. (see code snippet)

But I can't convert the OLE Object from db1(Access database) into a c# Bitmap object.
I have tried offset value from 0 to pictureData.Length. (see code snippet)

Here is a link to my sample database called db1.mdb
     http://www.mediafire.com/?1dgohmwqmmu
            OleDbConnection conn = new OleDbConnection("MyConnectionString");
            conn.Open();
            OleDbCommand query = new OleDbCommand("SELECT fldOLE FROM Table1", conn);
            byte[] pictureData = (byte[])query.ExecuteScalar();
            offsetValue = 78;
            Stream stream = new MemoryStream();
            stream.Write(pictureData, offsetValue, pictureData.Length - offsetValue);
            Image picture = Image.FromStream(stream);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of puppydogbuddy
puppydogbuddy

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account