Solved

Adding/Retrieving Images in Ole Object Fields

Posted on 1998-04-29
8
500 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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 100 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AutoCad licenses 9 71
passing parameter in sql procedure 9 63
Run code from text file in vb 1 65
Excel VBA, find a string in a column, update a cell 7 81
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this tutorial viewers will learn how to create blended and gradiated shapes in Illustrator using the blend tool Draw two shapes, one of them in a different color: Select both and create a blend by going to Object > Blend > Make: Blends can also b…
Not only does Prezi allow you to create non-linear presentations, it also makes it easy to apply transition animations between your frames. Learn how to apply a fade-in transition to select items and entire frames in this tutorial Select "Edit Path"…

810 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