Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding/Retrieving Images in Ole Object Fields

Posted on 1998-04-29
8
Medium Priority
?
511 Views
Last Modified: 2013-11-25
I need to store images (jpg, gif, bmp, whatever) in Ole Object fields (Long Binary) in an MS Access table.  I am able to add an image via Access, however I cannot retrieve the image thru VB.

I need to be able to add several images from the Table to an ImageList control for use by items in a ListView control.

I tried using the GetChunk method and FieldSize property for the Field, but am having little luck.

Any suggestions?
0
Comment
Question by:mattyboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 2

Expert Comment

by:marti
ID: 1434488
One possible solution:
Use picture/image bound to a data control.
0
 

Author Comment

by:mattyboy
ID: 1434489
I have tried that already.  I get error 481 "Invalid Picture".  I have tried using icons, bitmaps, wmf files, jpgs, gifs, you name it.

mattyboy
0
 
LVL 2

Expert Comment

by:lmorris
ID: 1434490
If you store an image as an OLE object in a database, then it's now an OLE object, not an image. What is stored in the database is some header information then the object information. So, if you stored an image in a database as an OLE object, then you must use the OLE control to display that image. Not an image or picture control.

To demonstrate, place the ole control on your form. It will bring up a dialog box asking a couple of questions, just click cancel.

Next, place a data control on the form. Set the databasename to your northwinds database. Mine is located in "C:\Program Files\DevStudio\VB\Nwind.mdb"

Set the recordsource to Employees.

Click on the OLE control and set it's datasource to Data1. Set it's datafield to photo.

Run the program and see your images.

If you want to convert the ole object back to an image, you'll need to strip off the OLE information at the begining of the file. Unfortunatly, I don't remember how many bytes that is.

Another alternative, is not to save the images in an OLE field. If I was using SQL Server, I would store it in a varbinary field.

And finally, the winning solution, is not to store images in a database at all. Store the image to a file, then just place the directory path and filename in the database. This has the advantages of keeping your database small/quick and allows you to easily work with the file.

If you have anyother question, just email me at lmorris@booksarefun.com
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mattyboy
ID: 1434491
Well, I need to put the images into an ImageList control.  I already know how to display the image from the Field using a data aware OLE Control.

I cannot use the path as a "pointer" to the image, because the database file is "mobile", and I cannot transport a bunch of images with it.  There are not that many images, so speed/size isn't really even an issue.

Ideally, I need to be able to load the image into an Image or PictureBox Control so I can add it to the ImageList, or be able to add it to the ImageList control directly.

If you can remember how to extract the image file from the field, please let me know, and I will more than gladly award you the points for the question!

mattyboy
0
 
LVL 7

Accepted Solution

by:
kamall earned 200 total points
ID: 1434492
mattyboy,
I had developed a project sometime ago that shows pictures stored in an access database into a picture box. If this solves your problem, comment me your e-mail address so I can send it to you. If not, please feel free to reject my answer.
Best regards
0
 
LVL 7

Expert Comment

by:kamall
ID: 1434493
mattyboy,
What VB version do you have?
0
 
LVL 2

Expert Comment

by:lmorris
ID: 1434494
   Dim db As Database
    Set db = DBEngine(0).OpenDatabase("NWind.mdb")
   
    Dim rs As Recordset
    Set rs = db.OpenRecordset("Employees")
   
    Dim lFileLength As Long
    lFileLength = rs.Fields("Photo").FieldSize
   
    Dim bChunk() As Byte
    ReDim Chunk(lFileLength)
   
    bChunk() = rs!photo.GetChunk(78, lFileLength)
   
    Dim lDataFile As Long
    lDataFile = FreeFile()
   
    Open "pictemp.bmp" For Binary Access Write As lDataFile
        Put lDataFile, , bChunk()
    Close lDataFile

    Image1.Picture = LoadPicture("pictemp.bmp")

0
 

Author Comment

by:mattyboy
ID: 1434495
kamall,
sorry it's been so long since i've visitted this site!  if you can still help me, i really could use the help!  my e-mail address is mattyboy@luckydevil.com

thanks!

matty

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
In this Micro Tutorial viewers will learn the basic shortcuts and functions of Illustrator. The viewer will learn about the paintbrush tool, anchor points, font sizing, and more.
Learn how to download your full Prezi presentation for offline presenting. Prezi doesn’t have to be viewed and shared in a web browser, even with a free account you can download your full presentation to share with others. Be sure to download any vi…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question