Question Retrieving a image from database

flashkid10

Member
Joined
Dec 9, 2016
Messages
16
Programming Experience
Beginner
I am currently learning how to work with databases within c#Winforms. I have created a column in the DList (the Access database) called "Cover". it stores attachments, most of them have an image in them. how do i extract the image (perferable both jpg and png) from the database (i already have the odbc connection) and display it in a picture box? I already have a system that extracts everything in the database and places them into a DataTable (called "LData"), can this be used to help?
 
Do you mean that*you have an ACCDB data file and your Cover column is type Attachment? If so then I'm afraid that you're out of luck. There's no support for working with Attachment columns in .NET. You can retrieve data successfully with a bit of messing around but there's no way to save it using ADO.NET. You have to use DAO and that's*very ugly.

All is not lost though. The Attachment data type is useful in an Access application because you can store multiple attachments in the one field. If you're not doing that then there wouldn't much advantage anyway. If I recall correctly, you should use the OLE Object data type. I think you'll also need to actually save the images from ADO.NET because saving to that data type in Access will produce a different storage format.

Assuming you do that, you will be retrieving and saving byte arrays, so you need to convert between those and Image objects. Here's an example of doing that:

Saving Images in Databases
 
Back
Top Bottom