Results 1 to 3 of 3

Thread: Retrieving a image from database

  1. #1
    flashkid10 is offline C# Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2016
    Posts
    16
    Rep Power
    7

    Retrieving a image from database

    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?

  2. #2
    jmcilhinney is offline C# Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    1,468
    Rep Power
    118
    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

  3. #3
    flashkid10 is offline C# Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2016
    Posts
    16
    Rep Power
    7
    Sorry it took so long to respond, I got it to work with the byte arrays

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •