Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 23rd, 2005, 05:37 AM
Registered User
Join Date: Jan 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

Old January 24th, 2005, 05:44 AM
Authorized User
Join Date: Jun 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts


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


Old August 17th, 2008, 06:42 AM
Registered User
Join Date: Aug 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to load multiple Images on the Form? shah123 C# 1 May 20th, 2007 09:28 PM
how to load images vaneza VB How-To 3 August 2nd, 2005 12:42 PM
pre load images error Adam H-W Javascript 10 January 7th, 2005 12:11 PM

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