Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 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
Updated 26-Nov-12 19:48pm
v2
Comments
Sergey Alexandrovich Kryukov 27-Nov-12 2:22am    
Did you try to find available answer?
--SA
WinnieMeeKun 27-Nov-12 4:24am    
i tried so many solution, still cannot solve the problem.
shivajikaka1988 3-May-13 10:35am    
this code is not working

1 solution

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
 
Share this answer
 
v3

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