Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi I want display pictures from sqlserver 2005 in to image control in my project on asp.net (c#).
note: In sql :picture's field type is image

Please help me,what do I do?

Thanks
Posted
Updated 14-Jun-12 20:39pm
v2

hi,
create a HttpHandler(ashx) page and write the following code in the handler file
C#
public void ProcessRequest (HttpContext context) 
    { 
          int ID;
          if (context.Request.QueryString["ID"] != null)
   ID= Convert.ToInt32(context.Request.QueryString["ID"]);
          else
            throw new ArgumentException("No parameter specified");

        byte[] imageData= ;// get the image data from the database using the ID Querystring by using your own business logic
        Response.ContentType = "image/jpeg";  
        Response.BinaryWrite(imageData);

    } 


and now the image control src will set like this:
ASP.NET
<asp:image id="imgTest" imageurl="myImage.ashx?ID=<someId>" xmlns:asp="#unknown" />

and little change in the config file
XML
<httphandlers>
  <add verb="*" path="img/*" type="DisplayImage" />
</httphandlers>
 
Share this answer
 
v3
Comments
Sandeep Mewara 15-Jun-12 1:51am    
One of the options. good answer. 5!
tanweer 15-Jun-12 2:56am    
thanks
thank you very much

know I want take image_id from textbox,what do I do?


because I can show image in the image control when I set :
imageurl= "mypic.ashx?ID=1"

but I want send image_id to this.....

what do I do?
thanks
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900