Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my code: Thanks inadvance
C#
private void button1_Click(object sender, EventArgs e)
       {
           SqlConnection con = new SqlConnection
                              (@"Data Source=CONA-A07\SQLEXPRESS;Initial Catalog=Pics;Integrated Security=True;Pooling=False");
           SqlCommand command = new SqlCommand
                               ("select PicName from Pictures where PicID =1", con);
           //for retrieving the image field in SQL SERVER EXPRESS
           //Database you should first bring
           //that image in DataList or DataTable
           //then add the content to the byte[] array.
           //That's ALL!
           SqlDataAdapter dp = new SqlDataAdapter(command);
           DataSet ds = new DataSet("Pictures");
           byte[] MyData = new byte[0];
           dp.Fill(ds, "Pictures");
           DataRow myRow;
           myRow = ds.Tables["Pictures"].Rows[0];
           MyData = (byte[])myRow["PicName"];
           MemoryStream stream = new MemoryStream(MyData);
           //With the code below, you are in fact converting the byte array of image
           //to the real image.
           pictureBox1.Image = Image.FromStream(stream,false ,true );
           //System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms, false, true);
       }


[edit]Code block added - OriginalGriff[/edit]
[edit2]Block end moved to get closing bracket on own line - OriginalGriff[/edit2]
Posted
Updated 28-Jul-11 9:38am
v3

1 solution

Are you sure it's "PicName" you want to retrieve? That sound a lot like a file name, rather than image data. What value do you get back from the database?
 
Share this answer
 
Comments
Amund Gjersøe 28-Jul-11 16:54pm    
Use Visual Studio to build the tableadapters and datasets, then you get strong typed datasets and thus it becomes easier to see the data type in each column.

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