Solved

Save and Load picture with Access database !

Posted on 2001-06-11
4
313 Views
Last Modified: 2012-08-13
Hi there !
I am using VB to access a table from Access database, please tell me with ADO code or DataEnv ActiveX how to :

1. Load picture from access database into Picture Box control ?

2. Save picture which selected in Picture Box control into Access Database ?

Notes:     I means save itself not it's link.

Thanks so much !
0
Comment
Question by:e9608092
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
sharmon earned 200 total points
ID: 6179990
If you are using ADO 2.5 or higher, you can use the stream object.  I will give you basics, if you know enough you'll be fine, if not, just ask and we'll help you.  If you are using ADO 2.1 or lower, this will not work, you'll have to use the old method, let us know and I am sure me or someone will give you that code, but I'd recommend using ADO 2.5 or higher.


This will read a steam from the database and store it as a file...replace d:\tmp.pic with whatever suits you.

If IsNull(rs.Fields("Photo").Value) Then
    Picture1.Picture = LoadPicture()
Else
    Dim adoStream As New ADODB.Stream
    adoStream.Type = adTypeBinary
    adoStream.Open
    adoStream.Write rs.Fields("Photo").Value
    adoStream.SaveToFile "d:\tmp.pic", adSaveCreateOverWrite
    Picture1.Picture = LoadPicture("d:\tmp.pic")
    adoStream.Close
    Set adoStream = Nothing
End If

If you want to write an image to the database you can use this...if you need to save your picturebox to a file first you can, but it will save as a bitmap and it will be alot bigger than a jpg or gif, so I would recommend grabbing the jpg or gif from the file instead of writing out the bitmap to the disk.

Dim adoStream As New ADODB.Stream

adoStream.Type = adTypeBinary
adoStream.Open
adoStream.LoadFromFile "d:\4.jpg"  'replace with your file

rs.AddNew
rs.Fields("Photo").Value = adoStream.Read
rs.Update

adoStream.Close
Set adoStream = Nothing
0
 
LVL 6

Expert Comment

by:sharmon
ID: 6179995
Also, if you don't already know, make sure that the field type for the photo column is OLE Object, in the example I assumed rs was the name of your recordset and that Photo was the name of the column in the recordset.  Since you seem to already know about ADO other than this, I didn't figure you'd need the whole thing explained from start to finish.  If so, just ask.
0
 
LVL 6

Expert Comment

by:simonbennett
ID: 6180245
Hi

My 2p

I have never used ado streaming, but it sounds similar to binary reads and writes. IMHO the only fast way to do this is to store the *path and filename* only in the database, and when you need to display it use the picture1.picture = loadpicture(<path and filename>).

The main reason for this is that your access db will increase in size very quickly, and the bigger it gets, the more likely it is to corrupt!

HTH and good luck

Simon
0
 

Author Comment

by:e9608092
ID: 6180552
Hello sharmon, Simon, Thank you, now I can continue my work with your instructions.


0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

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