sam samuel

sam samuel

  • NA
  • 112
  • 6.3k

Selecting image from database after user login

Mar 1 2017 8:14 AM
i have done for insering and selecting code using handler.ashx for selecting the photo
with the help of button click i get the use photo i want to get when the pageload itself with the help of handler page 
 
 ///PhotoHandler.ashx
<%@ WebHandler Language="C#" Class="PhotoHandler" %>
using System;
using System.Web;
public class PhotoHandler : IHttpHandler {
public void ProcessRequest (HttpContext context)
{
{
System.Data.SqlClient.SqlDataReader rdr = null;
System.Data.SqlClient.SqlConnection conn = null;
System.Data.SqlClient.SqlCommand selcmd = null;
try
{
conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["studentConnectionString"].ConnectionString);
selcmd = new System.Data.SqlClient.SqlCommand("select Image from User_Table where id=" + context.Request.QueryString["imgID"], conn);
conn.Open();
rdr = selcmd.ExecuteReader();
while (rdr.Read())
{
context.Response.ContentType = "image/jpg";
context.Response.BinaryWrite((byte[])rdr["Image"]);
}
if (rdr != null)
rdr.Close();
}
finally
{
if (conn != null)
conn.Close();
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
 

Answers (2)