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 ImageName FROM Image WHERE Department='OSA REWORK'", con));
                    DataSet dataSet = new DataSet();
                    dataAdapter.Fill(dataSet, "Image");
 if (dataSet.Tables["Image"].Rows.Count > 0)
                    {
 
                        MemoryStream ms = new MemoryStream((byte[])dataSet.Tables["Image"].Rows[0]["ImageName"]);
                        ms.Position = 0;
                       
                 pictureBox1.Image = Image.FromStream(ms);//>error        
            }
Posted 26-Nov-12 20:45pm
Edited 26-Nov-12 20:48pm
__TR__28.9K
v2
Comments
Sergey Alexandrovich Kryukov at 27-Nov-12 2:22am
   
Did you try to find available answer?
--SA
WinnieMeeKun at 27-Nov-12 4:24am
   
i tried so many solution, still cannot solve the problem.
shivajikaka1988 at 3-May-13 10:35am
   
this code is not working

1 solution

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

Solution 1

This rather boring question is asked so frequently that answering again would be wrong. Start with looking for existing answers:
http://www.codeproject.com/search.aspx?doctypeid=5&q=database+%28image+OR+images%29+PictureBox[^] (40 results),
http://www.codeproject.com/search.aspx?doctypeid=5&q=database+%28image+OR+images%29[^] (1326 results).
 
The number of found results shown at the moment of writing.
 
[EDIT]
 
In your case, you need to debug your code to see what's in the stream. For a test, you could simply copy your stream to a file stream to see if it's a valid file or not. It could be incorrectly written in first place. It could be a file name instead of file content — many different problems are possible.
 
—SA
  Permalink  
v3

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

  Print Answers RSS
0 OriginalGriff 7,105
1 DamithSL 5,079
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,617
4 Kornfeld Eliyahu Peter 4,384


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 27 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