Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to retrive the image from database to my picturebox for that i use this code below sis the code.
C#
SqlConnection connect = new SqlConnection(@"Data Source=USER;Initial Catalog=SAVERETRIVEDEMO;Integrated Security=True");
            SqlCommand command = new SqlCommand
                                ("select Image from save&Retriveimagedemo where ID=1", connect);
            //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("MyImages");

            byte[] MyData = new byte[0];

            dp.Fill(ds, "MyImages");(HERE I GOT ERROR INCORRECT SYNTAX NEAR SAVE KEYWORD)
            DataRow myRow;
            myRow = ds.Tables["MyImages"].Rows[0];

            MyData = (byte[])myRow["fldPic"];

            MemoryStream stream = new MemoryStream(MyData);
            //With the code below, you are in fact converting the byte array of image
            //to the real image.
            pictureBox2.Image = Image.FromStream(stream);
        } 




Plzz help me how to retive the image from database to picturebox and also want the byte array in which the image is retrive.plz give appropriate code for that.. plz its ugent.
Posted
Updated 24-Mar-15 21:48pm
v2

1 solution

I've formatted it a bit so it can be read properly.

Your error is in the name of your table...if you have special characters in your table names (such as &) you should use it with square brackets like this: [save&Retrieveimagedemo]


If this helps please take time to accept the solution. Thank you.
 
Share this answer
 
Comments
Member 11057488 25-Mar-15 5:58am    
Thank you sir.. This is helpful for me.

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