Hi
I've only done this from a win forms app not a web app so you might need to change one or two things to get it to work.
To load the image from the database I retrieve the image from the DB and place it into a Byte(), on binding the datato the picture box I load the Byte() into a memorystream and then load that into the picture box.
_User.Photo has the image in binary format loaded from the stored procedure in an arraylist.
Dim msData As New MemoryStream(CType(_User.Photo, Byte()))
'insert image into picture box from database
picUserImage.Image = Image.FromStream(msData)
to be able to save theimage back to the database use the following function
Private Function ImageToMemory() As Byte()
'================================================= ==================='Name:Image To Memory
'Purpose:copies the image stored in a picture box and returns it to
' a memory stream so the image can be saved back to the database.
'Returns:<insert any return information here>
'Input:<insert any input parameters here>
'Output:<insert any output parmeters here>
'Author:Duncan Faulkner
'Date Created:April 2004
'================================================= ==================='Last Modified:
'<insert authors name here>
'<insert reason for change here>
'================================================= ===================
'retrieve image in picture box to stream for saving in database
Dim ms As MemoryStream = New MemoryStream
picUserImage.Image.Save(ms, Imaging.ImageFormat.Jpeg)
Dim bytBlobdata(CType(ms.Length, Int32) - 1) As Byte
ms.Position = 0
ms.Read(bytBlobdata, 0, CType(ms.Length, Int32))
Return bytBlobdata
End Function
to call this function use
_User.Photo = ImageToMemory()
then call the save stored procedure, remember to include in your paramaters collection the image length, and the image
Params(1) = New SqlParameter("@Data", SqlDbType.Image, users.Photo.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, users.Photo)
Params(1).value = users.Photo
HTH
Duncan
|