Click here to Skip to main content
15,666,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Updated 22-Nov-12 14:15pm
Braj_12 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


Please update row number with 0 as below.
MemoryStream ms = new MemoryStream((byte[])dataSet.Tables["PlantLayout"].Rows[0]["imageContent"]);
Hope this will help you.
Share this answer
WinnieMeeKun 22-Nov-12 4:31am    
i change it already. But still can'
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.
Share this answer
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)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900