Click here to Skip to main content
13,005,644 members (66,225 online)
Rate this:
Please Sign up or sign in to vote.
See more:
SqlDataAdapter dataAdapter = new SqlDataAdapter(new SqlCommand("SELECT imageContent FROM PlantLayout WHERE ID='PL001'", con));
                      DataSet dataSet = new DataSet();
                        if (dataSet.Tables["PlantLayout"].Rows.Count>0)
                                                        MemoryStream ms = new MemoryStream((byte[])dataSet.Tables["PlantLayout"].Rows[0]["imageContent"]);
                           pictureBox1.Image = Image.FromStream(ms);-->error place

***this is the code for display image but unsuccess.and display message "parameter is not valid"...Can someone tell me how to solve this problem? thanks.
Posted 20-Nov-12 21:58pm
Updated 22-Nov-12 14:15pm
BMS121 21-Nov-12 4:03am
There is the size of byte array is ZERO. So this may b ur error.
OriginalGriff 21-Nov-12 4:08am
No - that is just a place filler (and a waste of code)
The zero length array reference is overwritten with the data read from the DataTable in the following line.
OriginalGriff 21-Nov-12 4:07am
What happens?
What should happen?
Do you get an error? If so, what?
Do you get the "Testing" message box?

Have you looked with the debugger to see what is going on?
WinnieMeeKun 21-Nov-12 4:12am
the testing message box is a testing...nothing... the output is nothing come out.. should be have image to fix this problem? thanks
WinnieMeeKun 21-Nov-12 21:29pm
Now i get the message is "Object reference not set to an instance of an object". Can someone help me to solve this problem????thanks
Jon Marlow 21-Nov-12 22:32pm
Your "Object reference not set to an instance of an object" error could be because there's no table called "PlantLayout" in your dataset. Try inspecting the object to see what it's name is or use the table index number.
WinnieMeeKun 22-Nov-12 2:10am
i used correct table name...but pop up this message..don't know y?
WinnieMeeKun 22-Nov-12 4:21am
hello! i know the problem already but don't how to solve.
The problem is "pictureBox1.Image = Image.FromStream(ms);"...But how to solve it??? any ideas???
pradiprenushe 23-Nov-12 1:09am
are you storing large image? try your code for small size image. I think this is memory problem.
WinnieMeeKun 25-Nov-12 20:09pm
oic...thanks for your info..i will try to resize it.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


Please update row number with 0 as below.
MemoryStream ms = new MemoryStream((byte[])dataSet.Tables["PlantLayout"].Rows[0]["imageContent"]);
Hope this will help you.
WinnieMeeKun 22-Nov-12 4:31am
i change it already. But still can'
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You haven't reset the position to the beginning of the stream after writing to it.

Try adding
ms.Position = 0;
before the line where you get the error.
WinnieMeeKun 22-Nov-12 19:55pm
hello..thanks for helping solve the problem..i already add this code but still cannot display 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
Web02 | 2.8.170627.1 | Last Updated 22 Nov 2012
Copyright © CodeProject, 1999-2017
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