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 | 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
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 6th, 2005, 02:21 PM
Registered User
Join Date: Jul 2005
Location: , , Thailand.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mojo
Default How to binding picture file in database ?

I stuck at this thing about 1-2 weeks and up until now I cant figure it out.
Please help me, thanks very much.

Reply With Quote
  #2 (permalink)  
Old September 7th, 2005, 06:49 PM
Friend of Wrox
Points: 894, Level: 11
Points: 894, Level: 11 Points: 894, Level: 11 Points: 894, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Sep 2005
Location: London, , United Kingdom.
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts


I have had to do exactly this before. The main bits of my code are below. I hope the syntax is right, as I converted it from c# and im not too experienced in vb...

To insert an Image object into a column, picture, we put the object into an intermediate MemoryStream, then read an array of bytes from it, as that is how it is stored in the database. For an Image myImage:

' save to intermediate MemoryStream
Dim ms As New MemoryStream()
myImage.Save(ms, myImage.RawFormat)

' read byte array from stream
Dim bytBLOB() As New Byte(ms.Length)
ms.Position = 0
ms.Read(bytBLOB, 0, Convert.ToInt32(ms.Length))

' create parameter to insert
Dim parImage As New SqlParameter("@picture", SqlDbType.VarBinary)
parImage.Size = ms.Length
parImage.Value = bytBLOB

' we can now use the parameter in an SqlCommand etc as ususal

To retrieve the image using a SqlDataReader, we reverse the process, but it is much easier:

' read the byte array from the data reader
bytBLOBData = CType(sqldatardr.Item("picture"), Byte());
' create another MemoryStream
Dim msBLOBData As New MemoryStream(bytBLOBData);
' read Image object from MemoryStream
Image myImage = System.Drawing.Image.FromStream(msmBLOBData);

Another method can be found at

Hope this helps
Philip Cole
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Display picture from database using JSP codes ban_gal Java Databases 6 May 30th, 2008 08:21 PM
trying to bind a picture box to an access database dups General .NET 0 July 20th, 2006 12:56 AM
How to save a picture in Microsoft Access Database Edward King Java Databases 0 January 4th, 2006 01:27 AM
retriving picture from database(sql) to <asp:image aspnet79434319 Classic ASP Basics 0 June 21st, 2005 01:29 AM
Inserting a picture from a database into Word fastcorvette Pro VB Databases 1 February 15th, 2005 07:02 PM

All times are GMT -4. The time now is 01:12 PM.

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