0

Hey All

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

3
Contributors
2
Replies
9
Views
6 Years
Discussion Span
Last Post by yousafc#
0

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......

0
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);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.