profya
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
A lot of lines, but good.
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").
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