Skip to main content

Posts

Showing posts with the label Retrive image from database and open in new page using asp.net

Retrive image from database and open in new page using asp.net

Retrive image from database and open in new page using asp.net MemoryStream mstream = new MemoryStream(); SqlConnection conn = new SqlConnection("Data Source=(local)\\sqlexpress;Initial Catalog=master;Integrated Security=True"); conn.Open(); SqlCommand cmd = new SqlCommand("select Image from student1 where Id=" + TextBox1.Text, conn); byte[] image = (byte[])cmd.ExecuteScalar(); mstream.Write(image, 0, image.Length); Bitmap bitmap = new Bitmap(mstream); Response.ContentType = "image/gif"; bitmap.Save(Response.OutputStream, ImageFormat.Gif); conn.Close(); mstream.Close();