Click here to Skip to main content
15,922,574 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
I am using following code to get data from database and load to picture box

VB
Dim vrPicFromDB = IO.File.ReadAllBytes(DsPic.tblPicTest.Item("Picture"))
        Dim ms As New MemoryStream(vrPicFromDB)
        PictureBox1.Image = Image.FromStream(ms)


It gives error on DsPic.tblPicTest.Item("Picture")) portion of the statement.
I also tried

VB
CByte(DsPic.tblPicTest.Item("Picture")))

but it gives the same error.

Please advise how to fix it.
Thanks
Furqan
Posted
Comments
Manas Bhardwaj 29-Jul-11 11:12am    
what is the error?

wait, you mentioned that you are trying to read bytes from database. What is File doing here then?

IO.File.ReadAllBytes

If you already saved your data in binary format, you might not need any conversion at all.
 
Share this answer
 
v2
Comments
Furqan Sehgal 29-Jul-11 12:31pm    
Thanks,
I also tried
Dim vrPicFromDB = DsPic.tblPicTest.Item("Picture")
but it did not work.......... The value is being stored in Bytes
Kschuler 29-Jul-11 16:09pm    
What error did you get when you tried this?
First of all, the parm for
IO.File.ReadAllBytes is a file path. If you are storing your image in bytes you don't need this.

Secondly, IO.File.ReadAllBytes Returns a Byte Array. Not a byte. That is why CByte doesn't work.

If you are having trouble understanding built in functions like that, try google or MSDN for help. For example, here is the documentation on ReadAllBytes[^].

Try declaring vrPicFromDB as a byte array and then just set it equal to DsPic.tblPicTest.Item("Picture").
 
Share this answer
 

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