p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB.NET (http://p2p.wrox.com/forumdisplay.php?f=83)
-   -   Load Images from and Save Images to a Database (http://p2p.wrox.com/showthread.php?t=24340)

cyndie January 23rd, 2005 05:37 AM

Load Images from and Save Images to a Database
 
hey guys,

im using Vb.Net to develop a web application.
n im using SQL server.
Now, i would like to load images to my page from database.
could anyone out there willing to help me?

thanks alot



Duncan January 24th, 2005 05:44 AM

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

jomar August 17th, 2008 06:42 AM

hi guys

im having a problem, can you please help me..
how can i load and save images in access using visual studio .net 2005.. it would really help me if you send it to my email address at jomarrueco@yahoo.com. thanks





All times are GMT -4. The time now is 02:50 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.