如何解决在.NET中解决web程序Image控件中显示数据库Blob字段图片的问题

步人甲 2004-11-22 02:23:11
我原来的数据库中存储图片用的是LongRow格式,现在改为了Blob格式,急需要解决在Image控件中显示图片的问题,请问如何读取数据库中读取Blob格式的文件,又如何绑定到Image控件上进行显示,请各位高手帮帮忙,最好能够写出代码,万分感激!如果分不够,请短信告知,一定追加分!
...全文
253 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
步人甲 2004-11-24
  • 打赏
  • 举报
回复
zhouyonghua0520() 按照你的方法解决问题,谢谢,但是需要安装一个OracleClient的Dll!结分!
skytear(将进酒)你的方法是解决SQLserver的,不管怎样,先谢了!
  • 打赏
  • 举报
回复
我原来用过的一段Show Picture的代码,图片是image格式的,可能不怎么好,但能用。其他地方,你还可以在
http://dotnet.aspx.cc/ 这个地方讲的很清楚。

你试试

private void ShowPicture()
{
string strSel="select content from tblitem where itemcode='"+Control1.Text+"' and sequence='"+Control2.Text+"'";
SqlDataAdapter da2 = new SqlDataAdapter(strSel,share.cn);
SqlCommandBuilder MyCB = new SqlCommandBuilder(da2);
DataSet ds2 = new DataSet("MyImages");
byte[] MyData= new byte[0];
da2.Fill(ds2, "MyImages");
if (ds2.Tables["MyImages"].Rows.Count>0)
{
DataRow myRow;
myRow=ds2.Tables["MyImages"].Rows[0];
if(myRow["Content"].ToString()!="")
{
MyData = (byte[])myRow["Content"];
int ArraySize = new int();
ArraySize = MyData.GetUpperBound(0);
string address=Server.MapPath("temp");
if(j==1)
{
System.IO.File.Delete(address+@"\"+"5.gif");
}
else
{
System.IO.File.Delete(address+@"\"+(j-1).ToString()+".gif");
}
if (j>5)
{
j=1;
}
try
{
System.IO.File.Delete(address+@"\"+j.ToString()+".gif");
}
catch
{}
FileStream fs = new FileStream(address+@"\"+j.ToString()+".gif",FileMode.OpenOrCreate,FileAccess.Write);
fs.Write(MyData, 0,ArraySize);
Image1.ImageUrl="temp"+"\\"+j.ToString()+".gif";
fs.Close();
j++;
Image1.Visible=true;
}
else
{
Image1.Visible=false;
}


}
}
xiaoslong 2004-11-23
  • 打赏
  • 举报
回复
帮你顶
zhouyonghua0520 2004-11-23
  • 打赏
  • 举报
回复
假设存图片的表为
image:
xh varchar2(5)
photo blob

string sXH = "12345"
OracleConnection conn = new OracleConnection("Password=test;User ID=test;Data Source=test");
string sSQL = "select photo from image where xh = '"+sXH+"'";
OracleDataAdapter adt = new OracleDataAdapter(sSQL,conn);
DataSet ds = new DataSet();
adt.Fill(ds);
//写临时文件
Byte[] FileByteArray;
object aaa = ds.Tables[0].Rows[0]["photo"];
FileByteArray = (Byte[])aaa;
string sPath = @"C:\result.jpg";
FileStream fs = new FileStream(sPath,FileMode.OpenOrCreate,FileAccess.Write,FileShare.None);
fs.Write(FileByteArray,0,FileByteArray.Length);
fs.Flush();
fs.Close();
Image.ImageUrl = sPath;

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧