图片显示不出来

wanggang780724 2007-01-04 05:10:04
各位帮忙看看我哪里写的不对
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 syid=3";
OleDbCommand command = new OleDbCommand(comm, accessConn);
OleDbDataReader reader = command.ExecuteReader();
if (reader.Read()) ;
{ Response.Clear();
Response.ContentType="image/gif";
Response.BinaryWrite((byte[])reader["zp"]);
Response.end()
}
accessConn.Close();
}

}
我的数据库是ACCESS数据库 存储照片的字段为ZP 谢谢
...全文
140 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanggang780724 2007-01-04
  • 打赏
  • 举报
回复
在调试的时候也能看到byte[]的维数是正确的
wanggang780724 2007-01-04
  • 打赏
  • 举报
回复
有可能 我上传了一张图片 在数据库里增加了一条记录 但数据库容量没有变 OLEDB字段我又看不到
孟子E章 2007-01-04
  • 打赏
  • 举报
回复
确保正确进行了存储
http://dotnet.aspx.cc/article/9154bc99-df64-4e2d-b096-26c99ce464be/read.aspx

111,104

社区成员

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

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

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