Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB Access
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..
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.'
pictures = Image.FromStream(ms);
Posted 10-Apr-13 13:35pm
Edited 10-Apr-13 14:13pm
v2
Comments
Sergey Alexandrovich Kryukov at 10-Apr-13 19:01pm
   
In what line?
—SA
arnoldxx at 10-Apr-13 19:11pm
   
sorry did not tell u guys bout the detail
in this line
pictures = Image.FromStream(ms)
:)
Sergey Alexandrovich Kryukov at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  

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

  Print Answers RSS
0 Kornfeld Eliyahu Peter 275
1 Maciej Los 204
2 Sergey Alexandrovich Kryukov 200
3 King Fisher 185
4 OriginalGriff 183
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100