图片无法显示
各位帮忙看看,我哪里写的不对
上传照片
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();
}
}
照片上传成功,但显示不出来.谢谢