日期:2014-05-17  浏览次数:20506 次

asp.net读取oracle二进制图片?
asp.net怎么读取、下载 用二进制 存在 oracle 的图片 和文件 ?
小弟现在在该一个站 以前用jsp+oracle 做的 现在 要改成 asp.net+oracle  
oracle 图片 和 上传的附件 文件 都是用二进制存的。。而却 图片和附件名称也存进去了。。。
在网上找了写方法 读出来 都是乱码。。。

------解决方案--------------------
参见
http://aspalliance.com/570_Read_and_Write_BLOB_Data_to_a_Database_Table_with_ODPNET.all
http://www.codeproject.com/Articles/13365/Insert-retrieve-an-image-into-from-a-blob-field-in
------解决方案--------------------
http://topic.csdn.net/u/20110303/21/1ec0fe60-fb22-44e8-b6ff-6b91cf7d81c4.html
------解决方案--------------------
1、显示图片
<%@ Page Language="C#" AutoEventWireup="true" %>

<script runat="server">

protected override void OnLoad(EventArgs e)
{
if (Request.QueryString["linkId"] != null)
{
BLL.DB_LINKS bll = new BLL.DB_LINKS();
Model.DB_LINKS m = bll.GetModel(Request.QueryString["linkId"].ToString());
if (m == null) return;

byte[] buffer = m.IMG;
if (buffer != null)
{
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer))
{
System.Drawing.Image image = System.Drawing.Image.FromStream(stream);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);

HttpContext.Current.Response.ContentType = "image/jpg";
if (image != null)
{
image.Save(HttpContext.Current.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
Response.Flush();
Response.End();
}

}
}
}

</script>

2、需要显示图片的调用
<div style="height: 50px; background: url(<%= Url.Content("~/DisplayImg.aspx?linkId="+ksList[i].LINKSID) %>) no-repeat; text-align:center; vertical-align:middle;">
<a href="<%= Url.Content(ksList[i].URL) %>" target="_blank" style="margin:0 0 0 0; color:#ffffff; font-size:24px;"> <%= ksList[i].LINKSTITLE %></a></div>

我这里是MVC 写的,但都是通用的LZ可以试试。