Wednesday, December 10, 2003

Display Image / Blob that is stored in database on webpage using ADODB.STREAM

Visual Basic Source code

Set objPhoto = CreateObject("ADODB.Stream")
objPhoto.Type = adTypeBinary
objPhoto.Open
objPhoto.Write (recData("Photograph"))
objPhoto.SaveToFile "./Images/Photo.jpg", adSaveCreateOverWrite
ImgPhoto.Picture = LoadPicture("./Images/Photo.jpg")
objPhoto.Close

ASP Source Code
const adTypeBinary = 1
const adSaveCreateOverWrite = 2
Set objPhoto = Server.CreateObject("ADODB.Stream")
objPhoto.Type = adTypeBinary
objPhoto.Open
objPhoto.Write (recData("Photograph"))
objPhoto.SaveToFile "./Images/Photo.jpg", adSaveCreateOverWrite
objPhoto.Close

Create a <IMG SRC="/Images/Photo.jpg">

**recData("Photograph") = A Recordset retrieved with the Photograph field

Feel free to use the code above. If it solves your problem, that's great. Otherwise, hope you found a site which has good source codes to share out by someone like me.