码迷,mamicode.com
首页 > 其他好文 > 详细

从blob字段读取图片 在浏览器显示

时间:2014-09-29 16:22:01      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:io   os   ar   sp   c   on   cti   amp   r   

public byte[] GetProImg(string JID)
{
byte[] Buffer = null;

using (OracleConnection conn = new OracleConnection(Pub.ConnectionString))
{
try
{
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "select PDC_FJ from tb t where JID= :p1";
cmd.Parameters.AddWithValue("p1", JID);
OracleDataReader dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
if (dr.Read())
{
OracleLob myLob = dr.GetOracleLob(0);
int myLength = Convert.ToInt32(myLob.Length);
Buffer = new byte[myLength];
myLob.Read(Buffer, 0, myLength);
}
dr.Close();
}
catch (System.Data.OracleClient.OracleException ex)
{
throw new Exception(ex.Message);
}
finally
{
conn.Close();
}

}
return Buffer;
}

img.aspx:

protected void Page_Load(object sender, EventArgs e)
{
JHAC.BLL.Product bllpro = new JHAC.BLL.Product();
string jid = "";
if (Page.Request["Jid"] != null && Page.Request["Jid"].ToString() != "")
{
jid = Page.Request["Jid"].ToString();
}
byte[] imgByte = bllpro.GetProImg(jid);
if (imgByte != null)
{
this.Response.Clear();
this.Response.BinaryWrite(imgByte);
}
}

从blob字段读取图片 在浏览器显示

标签:io   os   ar   sp   c   on   cti   amp   r   

原文地址:http://www.cnblogs.com/handsomer/p/4000192.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!