Muhammad imran

Muhammad imran

  • NA
  • 16
  • 6.6k

Images retrieval from database issue

May 15 2013 4:14 PM
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)