Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create a <code>generic http handler</code> as follows</p> <pre><code>using System; using System.Configuration; using System.Web; using System.IO; using System.Data; using System.Data.SqlClient; public class ShowImage : IHttpHandler { public void ProcessRequest(HttpContext context) { Int32 empno; if (context.Request.QueryString["id"] != null) empno = Convert.ToInt32(context.Request.QueryString["id"]); else throw new ArgumentException("No parameter specified"); context.Response.ContentType = "image/jpeg"; Stream strm = ShowEmpImage(empno); byte[] buffer = new byte[4096]; int byteSeq = strm.Read(buffer, 0, 4096); while (byteSeq &gt; 0) { context.Response.OutputStream.Write(buffer, 0, byteSeq); byteSeq = strm.Read(buffer, 0, 4096); } //context.Response.BinaryWrite(buffer); } public Stream ShowEmpImage(int empno) { string conn = ConfigurationManager.ConnectionStrings["EmployeeConnString"].ConnectionString; SqlConnection connection = new SqlConnection(conn); string sql = "SELECT empimg FROM EmpDetails WHERE empid = @ID"; SqlCommand cmd = new SqlCommand(sql,connection); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@ID", empno); connection.Open(); object img = cmd.ExecuteScalar(); try { return new MemoryStream((byte[])img); } catch { return null; } finally { connection.Close(); } } public bool IsReusable { get { return false; } } } </code></pre> <p>and display image as follow</p> <pre><code> Image1.ImageUrl = "~/ShowImage.ashx?id=" + id; </code></pre> <p>There are some links below <br/> <a href="https://stackoverflow.com/questions/13432381/showing-image-in-gridview-from-the-database">Showing image in GridView from the database?</a><br/> <a href="https://stackoverflow.com/questions/2482104/how-to-show-a-image-in-database-in-the-image-control-of-asp-net">How to show a image in database in the image control of Asp.net?</a><br/> <a href="https://stackoverflow.com/questions/6987433/display-image-from-database-in-asp-net-with-c-sharp">Display image from database in ASP.net with C#</a><br/> <a href="http://www.dotnetcurry.com/ShowArticle.aspx?ID=129" rel="nofollow noreferrer">http://www.dotnetcurry.com/ShowArticle.aspx?ID=129</a></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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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