Author: getchinna_sv | Posted on: 3/11/2009 6:16:51 AM | Views : 245

I am retrieving the Image(Binary format) in the database using HttpHandler...like this...


public class Handler : IHttpHandler

{


public void ProcessRequest(HttpContext context)

{

SqlConnection myConnection = new SqlConnection(@"integrated security=yes;data
source=.\sqlexpress;database=aaa");

myConnection.Open();

string sql = "Select Image_Content from myImages where Img_Id=@ImageId";

SqlCommand cmd = new SqlCommand(sql, myConnection);

cmd.Parameters.Add("@ImageId", SqlDbType.Int).Value =
context.Request.QueryString["id"];

cmd.Prepare();

SqlDataReader dr = cmd.ExecuteReader();

dr.Read();

context.Response.ContentType = dr["Image_Type"].ToString();

context.Response.BinaryWrite((byte[])dr["Image_Content"]);

dr.Close() ...

Go to the complete details ...