Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
SqlDataAdapter dataAdapter = new SqlDataAdapter(new SqlCommand("SELECT imageContent FROM PlantLayout WHERE ID='PL001'", con));
                      DataSet dataSet = new DataSet();
                      dataAdapter.Fill(dataSet);
                      
 
                        if (dataSet.Tables["PlantLayout"].Rows.Count>0)
                      {
                                                        MemoryStream ms = new MemoryStream((byte[])dataSet.Tables["PlantLayout"].Rows[0]["imageContent"]);
ms.Position=0;
                           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 22:58pm
Edited 22-Nov-12 15:15pm
v6
Comments
BMS121 at 21-Nov-12 4:03am
   
There is the size of byte array is ZERO. So this may b ur error.
OriginalGriff at 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 at 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 at 21-Nov-12 4:12am
   
the testing message box is a testing...nothing... the output is nothing come out.. should be have image display.how to fix this problem? thanks
WinnieMeeKun at 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 at 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 at 22-Nov-12 2:10am
   
i used correct table name...but pop up this message..don't know y?
WinnieMeeKun at 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 at 23-Nov-12 1:09am
   
are you storing large image? try your code for small size image. I think this is memory problem.
WinnieMeeKun at 25-Nov-12 20:09pm
   
oic...thanks for your info..i will try to resize it.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
Please update row number with 0 as below.
MemoryStream ms = new MemoryStream((byte[])dataSet.Tables["PlantLayout"].Rows[0]["imageContent"]);
Hope this will help you.
  Permalink  
Comments
WinnieMeeKun at 22-Nov-12 4:31am
   
i change it already. But still can't...how?
Rate this: bad
good
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.
  Permalink  
v2
Comments
WinnieMeeKun at 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
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 22 Nov 2012
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