主题:sql中图片的存取显示问题?????
在数据库中保存时,使用语句:
Stream imgdatastream =hif.PostedFile.InputStream;
int imgdatalen =hif.PostedFile.ContentLength;
string imgtype =hif.PostedFile.ContentType;
byte[] imgdata = new byte[imgdatalen];
int n = imgdatastream.Read(imgdata,0,imgdatalen);
string sqlzp="insert into PrjImageInfo(id,photo,phototype,photolength,time,name,sex,birthday,idnumber,married,politics,university,degree,company) values(";
sqlzp=sqlzp+"'"+xmbh.Text+"','"+imgdata+"','"+imgtype+"','"+imgdatalen+"','"+time.Text+"','"+name.Text+"','"+sex.Text+"','"+birthday.Text+"','"+idnumber.Text+"','"+married.Text+"','"+politics.Text+"','"+university.Text+"','"+degree.Text+"','"+company.Text+"')";
conn.open();
SqlCommand cmdzp=new SqlCommand(sqlzp,conn);
cmdzp.ExecuteNonQuery();
conn.Close();
来完成数据库的图片保存。
使用下列语句,来完成数据库中图片的提取。
string sql="select * from PrjImageInfo where id='"+xmbh2+"'";
conn.open();
SqlCommand cmd=new SqlCommand(sql,conn);
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
int imgdatalen=Convert.ToInt32(dr["photolength"].ToString());
string imgtype =dr["phototype"].ToString();
byte[] imgdata = new byte[imgdatalen];
Response.ContentType =imgtype;
Response.BinaryWrite((byte[])dr["photo"]);
//Response.OutputStream.Write((byte[])dr["photo"], 0,imgdatalen);
}
dr.Close();
conn.Close();
}
但是页面显示不是图片,而是:
System.Byte[]
什么原因呢?谢谢大侠了!谢谢!
Stream imgdatastream =hif.PostedFile.InputStream;
int imgdatalen =hif.PostedFile.ContentLength;
string imgtype =hif.PostedFile.ContentType;
byte[] imgdata = new byte[imgdatalen];
int n = imgdatastream.Read(imgdata,0,imgdatalen);
string sqlzp="insert into PrjImageInfo(id,photo,phototype,photolength,time,name,sex,birthday,idnumber,married,politics,university,degree,company) values(";
sqlzp=sqlzp+"'"+xmbh.Text+"','"+imgdata+"','"+imgtype+"','"+imgdatalen+"','"+time.Text+"','"+name.Text+"','"+sex.Text+"','"+birthday.Text+"','"+idnumber.Text+"','"+married.Text+"','"+politics.Text+"','"+university.Text+"','"+degree.Text+"','"+company.Text+"')";
conn.open();
SqlCommand cmdzp=new SqlCommand(sqlzp,conn);
cmdzp.ExecuteNonQuery();
conn.Close();
来完成数据库的图片保存。
使用下列语句,来完成数据库中图片的提取。
string sql="select * from PrjImageInfo where id='"+xmbh2+"'";
conn.open();
SqlCommand cmd=new SqlCommand(sql,conn);
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
int imgdatalen=Convert.ToInt32(dr["photolength"].ToString());
string imgtype =dr["phototype"].ToString();
byte[] imgdata = new byte[imgdatalen];
Response.ContentType =imgtype;
Response.BinaryWrite((byte[])dr["photo"]);
//Response.OutputStream.Write((byte[])dr["photo"], 0,imgdatalen);
}
dr.Close();
conn.Close();
}
但是页面显示不是图片,而是:
System.Byte[]
什么原因呢?谢谢大侠了!谢谢!