Click here to Skip to main content
14,735,318 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have saved an image in database using following code.
vrPicHolder = IO.File.ReadAllBytes(ofd.FileName)
Dim drPic As DataRow
drPic = DsPic.tblPicTest.NewRow
drPic.Item("Picture") = vrPicHolder

Now I want to display this image in a picture box. I tried
PictureBox1.Image = Image.FromFile(vrPicHolder)

But it says can not convert Byte() to string. Please advise how to load this picture. Thanks Furqan
Updated 28-Jul-11 22:33pm

1 solution

You don't want to try to read the file again - you saved the file content, not it's name so it's can't be opened and you don't want to convert it to a string. You want to convert it to an Image.
Dim ms As New MemoryStream(vrPicHolder)
PictureBox1.Image = Image.FromStream(ms)
Furqan Sehgal 29-Jul-11 4:17am
Thank you very much.
please also advise how to call it in SSRS. From file I could use expression
what about stream?
OriginalGriff 29-Jul-11 4:24am
That is probably a new question - but have a look at google, and here:
Furqan Sehgal 29-Jul-11 5:48am
Problem in your above code
Dim ms As New MemoryStream(vrPicHolder)
PictureBox1.Image = Image.FromStream(ms)

Overload resolution error is being given on ms
I also added Imports System.IO
OriginalGriff 29-Jul-11 5:51am
Do you import System.Drawing?
Furqan Sehgal 29-Jul-11 7:03am
Yes I did. Error on ms is

Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
'Public Sub New(buffer() As Byte)': Argument matching parameter 'buffer' narrows from 'Object' to '1-dimensional array of Byte'.
'Public Sub New(capacity As Integer)': Argument matching parameter 'capacity' narrows from 'Object' to 'Integer'. D:\VS2008\PicToDatabase\PicToDatabase\Form1.vb 21 13 PicToDatabase
OriginalGriff 29-Jul-11 7:09am
Ah! It's the declaration of vrPicHolder - cast it to byte array and it should be fine.
Furqan Sehgal 29-Jul-11 9:42am
It works ! thanks sir
OriginalGriff 29-Jul-11 9:48am
You are welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900