Link to home
Start Free TrialLog in
Avatar of profya
profyaFlag for Sudan

asked on

How to save and retrieve a SQL Server 7.0 BOLOB photo field.

I read Microsoft advices in saving and retrieving photo fields in VB using appendchunck and getchunck functions but I failed to make it work, a typical guranteed-working example would be useful. I don't wanna use data control, all are unbounded controls and the receiving control is a standard picture box.
Avatar of sharmon
sharmon

I just answered this for someone else, you can use the chunk method, but I like the stream object better.  As long as you can use ADO 2.5 or higher this is how you can do it.

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
ASKER CERTIFIED SOLUTION
Avatar of deighton
deighton
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of profya

ASKER

A lot of lines, but good.