DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • How To Generate Scripts of Database Objects in SQL Server
  • Different Ways To Rename Database Objects
  • Different Ways to Search Database Objects
  • JSON-Based Serialized LOB Pattern

Trending

  • Best Practices for Writing Clean Java Code
  • Spring WebFlux Retries
  • A Guide to Data-Driven Design and Architecture
  • Exploring Edge Computing: Delving Into Amazon and Facebook Use Cases
  1. DZone
  2. Data Engineering
  3. Databases
  4. Display an OLE Object from a Microsoft Access Database using OLE Stripper

Display an OLE Object from a Microsoft Access Database using OLE Stripper

Amir Ahani user avatar by
Amir Ahani
·
Mar. 15, 12 · Interview
Like (0)
Save
Tweet
Share
10.10K Views

Join the DZone community and get the full member experience.

Join For Free

In database programming, it happens a lot that you need to bind a picture box to a field with type of photo or image. For example, if you want to show an Employee’s picture from Northwind.mdb database, you might want to try the following code:

picEmployees.DataBindings.Add(“Image”, bsEmployees, “Photo”, true);

This code works if the images are stored in the database with no OLE header or the images stored as a raw image file formats. As the pictures stored in the Northwind database in are not stored in raw image file formats and they are stored as an OLE image documents, then you have to strip off the OLE header to work with the image properly.

Binding imageBinding = new Binding("Image", bsEmployees,
                                   "ImageBlob.ImageBlob", true);
imageBinding.Format += new ConvertEventHandler(this.PictureFormat);
 
private void PictureFormat(object sender, ConvertEventArgs e)
{
    Byte[] img = (Byte[])e.Value;
    MemoryStream ms = new MemoryStream();
    int offset = 78;
    ms.Write(img, offset, img.Length - offset);
    Bitmap bmp = new Bitmap(ms);
    ms.Close();
    // Writes the new value back
    e.Value = bmp;
}

Fortunately, there are some overload methods in .NET Framework to take care of this mechanism, but it cannot be guaranteed whether you need to strip off the OLE object by yourself or not. For example, you can use the following technique to access the images of the Northwind.mdb that ships with Microsoft Access and they will be rendered properly.

picEmployees.DataBindings.Add(“Image”, bsEmployees, “Photo”, true,
DataSourceUpdateMode.Never, new Bitmap(typeof(Button), “Button.bmp”));

Unfortunately, there are some scenarios that you need a better solution. For example, the Xtreme.mdb database that ships with Crystal Reports has a photo filed that cannot be handled by the preceding methods. For these complex scenarios, you can download the OLEStripper classes from here and re-write the PictureFormat method as it is shown below:

private void PictureFormat(object sender, ConvertEventArgs e)
{
     // photoIndex is same as Employee ID
     int photoIndex = Convert.ToInt32(e.Value);
     // Read the original OLE object
     ReadOLE olePhoto = new ReadOLE();
 
     string PhotoPath = olePhoto.GetOLEPhoto(photoIndex);
 
     // Strip the original OLE object
     StripOLE stripPhoto = new StripOLE();
 
     string StripPhotoPath = stripPhoto.GetStripOLE(PhotoPath);
 
     FileStream PhotoStream = new FileStream(StripPhotoPath
                                           , FileMode.Open);
 
     Image EmployeePhoto = Image.FromStream(PhotoStream);
 
     e.Value = EmployeePhoto;
 
     PhotoStream.Close();
 
}

 

 

Microsoft Access Database Object (computer science)

Published at DZone with permission of Amir Ahani, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Generate Scripts of Database Objects in SQL Server
  • Different Ways To Rename Database Objects
  • Different Ways to Search Database Objects
  • JSON-Based Serialized LOB Pattern

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: