【发布时间】:2013-02-02 19:39:13
【问题描述】:
如何使用 c# 从 asp.net 中的 sql 数据库中检索图像。
我想从数据库中检索图像文件,然后在标签中显示图像。
我尝试了这段代码,但它不起作用
aspx
<asp:Image ID="Image1" runat="server" ImageUrl="" Height="150px" Width="165px" />
后面的代码
Byte[] bytes = (Byte[])ds.Tables[0].Rows[0]["image"];
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "image/jpg";
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
如何给出这张图片的ImageUrl=""的链接???
【问题讨论】:
-
定义
not working,你遇到了什么错误? -
哦,MIME 是
image/jpeg不是image/jpg。 -
这是页面还是通用处理程序 (ashx)?
-
你还需要 Response.Clear()
-
@AhmadAbbasi 这是一个文件名而不是一个 URI。但是,如果您通过寻址
http://domain/Student.aspx返回图像,那么您的 ImageUrl 将是:http://domain/Student.aspx。
标签: c# asp.net sql-server httphandler