10
Answers

Images retrieval from database issue

Muhammad imran

Muhammad imran

11y
1.2k
1
Hello
i am trying to retrieve images from database.But my code is not working.Please help me.Thanks

SqlConnection conn = new SqlConnection("Data Source=localhost;Initial Catalog=company;Integrated Security=True");
            conn.Open();
            SqlCommand cmd = new SqlCommand("select image from image", conn);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read()) //yup we found our image
            {
                Response.ContentType = dr["Image"].ToString();
                Response.BinaryWrite((byte[])dr["Image"]);
                Response.Write(System.Environment.NewLine);               
            }

            Response.Close();
            conn.Close();
Answers (10)