Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 23rd, 2005, 04:37 AM
Registered User
 
Join Date: Jan 2005
Location: , , .
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


Reply With Quote
  #2 (permalink)  
Old January 24th, 2005, 04:44 AM
Authorized User
 
Join Date: Jun 2003
Location: Norfolk, , United Kingdom.
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #3 (permalink)  
Old August 17th, 2008, 06:42 AM
Registered User
 
Join Date: Aug 2008
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 11:11 AM



All times are GMT -4. The time now is 01:56 AM.


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