Click here to Skip to main content
11,922,641 members (57,252 online)
Rate this:
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)
                        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
Sergey Alexandrovich Kryukov 10-Apr-13 19:01pm
In what line?
arnoldxx 10-Apr-13 19:11pm
sorry did not tell u guys bout the detail
in this line
pictures = Image.FromStream(ms)
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.

1 solution

Rate this: bad
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:[^].

After that, just read the image.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151125.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2015
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