从数据库检索图像

问题描述:

朋友,
我想从数据库中检索图像并显示在图像控件中.我在这里遇到问题.
请帮帮我吗?
我想在不使用通用处理程序(.ashx)的情况下检索图像.

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

询问者的要求如下:
1. 先尝试您要做什么!
2.制定看起来像问题/无法解决的问题.

现在,请看这里:使用ASHX文件检索数据库映像 [^ ]

有关更多信息: ^ ]
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[^]


您是否阅读了发布问题的规则?如果有的话,也许您错过了说明以下内容的那一项:
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?


让我告诉你它是如何完成的...
^ ]
哇!!!!大约有44,000,000个结果.


Let me show you how it is done...
Retrieve Image From Database[^]
Wow!!!! About 44,000,000 results.


非常感谢您对我的回复...........


Home.aspx
Many thanks given reply to me...........


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




Showimage.ashx




Showimage.ashx

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





AdminHome.aspx

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



AdminHome.aspx的源代码部分



source part of AdminHome.aspx

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



Web.Config




Web.Config


<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..........