Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to retrieve and display image from database in asp.net
    primarykey
    data
    text
    <p>I am going to show images from database as the user input image id. and I have to show it in picture box below it.</p> <p>I used this code to convert base64string to image</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["ImageID"] != null) { string ImgData = Request.QueryString["ImageID"].ToString(); Byte[] bytes = Convert.FromBase64String(ImgData); Response.Buffer = true; Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "image/jpg"; Response.AddHeader("content-disposition", "attachment;"); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); } } } </code></pre> <p>and my main webpage sourcecode is</p> <pre><code>protected void Button1_Click(object sender, EventArgs e) { NpgsqlCommand cmd = null; string selPhoto = @"select * from photodetails where photoid=@photoid"; System.Drawing.Image newImage; string tempfilename=@"C:\Users\Public\temp_image"; try { cmd = new NpgsqlCommand(selPhoto, con); cmd.Parameters.Add("@photoid",Convert.ToInt16(txtpid.Text)); if (con.State == ConnectionState.Open) con.Close(); con.Open(); NpgsqlDataReader drphoto = cmd.ExecuteReader(); while (drphoto.Read()) { //System.IO.Stream fs = FileUpload1.PostedFile.InputStream; //System.IO.BinaryReader br = new System.IO.BinaryReader(fs); Byte[] bytes = (byte[])drphoto["photo_bytearr"]; //br.ReadBytes((Int32)fs.Length); string base64String = Convert.ToBase64String(bytes, 0, bytes.Length); img1.ImageUrl = @"http://localhost:29450/SampleWeb/showimg.aspx?ImageData=" + Convert.ToBase64String(bytes); } } catch (Exception ex) { } } </code></pre> <p>but still it doesn't showing image?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload