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

x
?
Solved

Save and Load picture with Access database !

Posted on 2001-06-11
4
Medium Priority
?
349 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
[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
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
sharmon earned 800 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

609 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