Click here to Skip to main content
14,301,895 members
Rate this:
Please Sign up or sign in to vote.
See more:
<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System.Drawing.Imaging;

public class Handler : IHttpHandler {

SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["Drawing1"].ConnectionString) ;
SqlCommand cmd;

public void ProcessRequest (HttpContext context)
{

cmd = new SqlCommand("select Img from Service_Name where Service_Id=1002", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
context.Response.ContentType = "image/png";//use ur image type
context.Response.BinaryWrite((byte[])reader["Img"]);
}
con.Close();
}

public bool IsReusable {
get {
return false;
}
}

}


page only contains <asp:Image ID="Image1" Width="200px" Height="200px" runat="server" ImageUrl="~/Handler.ashx"/>

and when i see source after execution the image shows "The image cannot be shown as it contains error"
Posted
Updated 22-Sep-13 3:52am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Check your image: it may be the way you inserted them, rather than how you extract it. This may help: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100