图片无法显示

wanggang780724 2007-01-04 12:16:48
各位帮忙看看,我哪里写的不对
上传照片
protected void Button1_Click1(object sender, EventArgs e)
{
int intImageSize;
string strImageType;
Stream ImageStream;
intImageSize = PersonImage.PostedFile.ContentLength;
strImageType = PersonImage.PostedFile.ContentType;
ImageStream = PersonImage.PostedFile.InputStream;
Byte[] imagecontent = new Byte[intImageSize];
ImageStream.Read(imagecontent, 0, intImageSize);
string ACS = System.Configuration.ConfigurationManager.AppSettings["ACCESSCONNECTIONSTRING"].ToString();
string accessString = ACS + Server.MapPath("数据库名称");
OleDbConnection accessConn = new OleDbConnection(accessString);
accessConn.Open();
string comm = "insert into syzp(syid,zp) values(3,'" + imagecontent + "')";
OleDbCommand command = new OleDbCommand(comm, accessConn);
try
{

command.ExecuteNonQuery();
accessConn.Close();
Response.Write("<font color=red>照片上传成功!</font>");
}
catch (OleDbException ex)
{
Response.Write("照片上传失败" + ex.ToString());
}

}
显示图片
public partial class main_displaysyzp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string ACS = System.Configuration.ConfigurationManager.AppSettings["ACCESSCONNECTIONSTRING"].ToString();
string accessString = ACS + Server.MapPath(数据库名称);
OleDbConnection accessConn = new OleDbConnection(accessString);
accessConn.Open();
string comm = "select * from syzp where id=3";
OleDbCommand command = new OleDbCommand(comm, accessConn);
OleDbDataReader reader = command.ExecuteReader();
if (reader.Read()) ;
{
Response.BinaryWrite((byte[])reader["zp"]);

}
accessConn.Close();
}

}
照片上传成功,但显示不出来.谢谢
...全文
174 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiatong1981 2007-01-04
  • 打赏
  • 举报
回复
娘子 快和牛魔王出来看上帝……

呵呵
孟子E章 2007-01-04
  • 打赏
  • 举报
回复
参考
http://dotnet.aspx.cc/article/ey1xldyv-pidf-43lo-1wfl-fmy5ale1f635/read.aspx
孟子E章 2007-01-04
  • 打赏
  • 举报
回复
if (reader.Read()) ;
{
Response.Clear();
Response.ContentType = "image/gif";//和你的类型有关系
Response.BinaryWrite((byte[])reader["zp"]);
Resposne.End();

}
wanggang780724 2007-01-04
  • 打赏
  • 举报
回复
试过上面的方法为什么还是不行
jackyped 2007-01-04
  • 打赏
  • 举报
回复
Response.BinaryWrite((byte[])reader["zp"]);

这个方法好狠

110,534

社区成员

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

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

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