Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hai guys..
i try to retrieve data from access to vb..
everthing work normally
but.. when i try to retrieve my image from my access
i wonder what happen to my code..
VB
Dim pc As Byte() = CType(rdr.Item("picture"), Byte())
                        Dim pictures As Image = Nothing
                        Using ms As New System.IO.MemoryStream(pc, True)
                            ms.Write(pc, 0, pc.Length)
                            pictures = Image.FromStream(ms)
                            ms.Close()
                        End Using
                        Form3.PictureBox1.Image = pictures

there is an error told me that 'Parameter is not valid.'
VB
pictures = Image.FromStream(ms);
Posted
Updated 10-Apr-13 13:13pm
v2
Comments
Sergey Alexandrovich Kryukov 10-Apr-13 19:01pm    
In what line?
—SA
arnoldxx 10-Apr-13 19:11pm    
sorry did not tell u guys bout the detail
in this line
pictures = Image.FromStream(ms)
:)
Sergey Alexandrovich Kryukov 17-Apr-13 0:30am    
Got it, thanks for clarification (always provide comprehensive exception information, and better show the point where the exception is thrown as a comment in your code).
The solution is clear and ready, please see.
—SA

1 solution

Your problem is writing to a stream and then reading an image from it. At the start of reading of the image, your position in stream is at the very end; so there is nothing to read, which throws an exception. Rewind the stream back to the beginning, reopen it.

You don't need to write bytes to the stream, they are already there. Use this constructor, with one parameter:
http://msdn.microsoft.com/en-us/library/e55f3s5k.aspx[^].

After that, just read the image.

—SA
 
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