Hey All

I would like to know how to retrieve a image from sql server database. im storing the path in the database..

Recommended Answers

All 2 Replies

Can you save image in folder(i.e. path saved in database) If Yes then just retrieve the path using query and display image in Picturebox/Datagridview.

Hope this will help......

SqlConnection connect = new SqlConnection
                           ("Data source =YS-8462BA359936;Initial Catalog = Schooldata;Integrated Security = True");
            SqlCommand command = new SqlCommand
                                ("select Picture from Picturestable where Studentid=@id", connect);
            command.Parameters.Add("@id", SqlDbType.Int).Value = txtstudentid.Text;
            
            SqlDataAdapter dp = new SqlDataAdapter(command);
            DataSet ds = new DataSet("Picturestable");

            byte[] MyData = new byte[0];

            dp.Fill(ds, "Picturestable");
            DataRow myRow;
            myRow = ds.Tables["picturestable"].Rows[0];

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

            MemoryStream stream = new MemoryStream(MyData);

            pictureBox1.Image = Image.FromStream(stream);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.