Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Friends,
i want to retrive image from Database and display in Image Control. I am getting Problem here.
please help me?
i want to retrive an image without using generic handler (.ashx). How
Posted
Updated 18-Apr-12 4:00am
v2
Comments
hamid-shrk 18-Apr-12 9:48am    
your field type in DB is "image" type or "varchar" ,... ?

Here is what is expected by enquirers:
1. TRY first what you want to do!
2. Formulate what was done by you that looks like an issue/not working.

For now, look here: Using ASHX files to retrieve DB images[^]

For more: Google search result[^]
 
Share this answer
 
Did you read the rules for posting a question? If you had, perhaps you missed the one that states:
1. Have you searched or Googled for a solution?

Let me show you how it is done...
Retrieve Image From Database[^]
Wow!!!! About 44,000,000 results.
 
Share this answer
 
Comments
bbirajdar 18-Apr-12 10:14am    
I agree.. +5
Many thanks given reply to me...........


Home.aspx
C#
Session["id"] = 1;
               Server.Transfer(@"Admin\AdminHome.aspx");



Showimage.ashx

C#
public void ProcessRequest(HttpContext ctx) 
    { 
        
        SqlConnection con = new SqlConnection("user id=sa;password=sa@123;database=img;server=.;");
        con.Open();       
        string x =ctx.Request.QueryString[0];
        SqlCommand cmd = new SqlCommand("select image_data,image_contenttype from images where image_pk=" +int.Parse(x), con);       
        SqlDataReader dr = cmd.ExecuteReader();
        dr.Read();
        ctx.Response.ContentType = dr["image_contenttype"].ToString();
        ctx.Response.BinaryWrite((byte[])dr["image_data"]);
        dr.Close();
        con.Close();
    } 




AdminHome.aspx

HTML
Image2.ImageUrl = "~/Admin/ShowImage.ashx?id=" + int.Parse(Session["id"].ToString());


source part of AdminHome.aspx

ASP.NET
<asp:image id="Image2" runat="server" height="164px" width="176px" xmlns:asp="#unknown" />


Web.Config


XML
<system.web>
        <compilation debug="true" targetFramework="4.0"/>
        <urlMappings enabled="true">
            <add url="~/AdminHome.aspx" mappedUrl="~/Admin/ShowImage.ashx"/>
        </urlMappings>
    </system.web>




it got Without any Error in this application....try it..........
 
Share this answer
 
v3

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