问题: 数据库中存储二进制图片,用js 不刷新页面显示图片
在此一并感谢wuya11(人生如梦)、cuike519(Thriller)
My_Page.aspx:
........
function Show_Picture_onclick()
{
document.getElementById("My_Picture").src="Show_Picture.aspx?id="+_studentid;
}
........
<img id="My_Picture" src="" alt="">
<input id="Show_Picture" type="button" value="显示图片" οnclick="Show_Picture_onclick()" />
........
Show_Picture.aspx:
.........
Show_Pictrue.aspx.cs:
........
protected void Page_Load(object sender, EventArgs e)
{
string studentid = Request.Params["id"].ToString();
if (!Page.IsPostBack)
{
CUntily Untily = new CUntily();
Untily.DBOpen();
string cmdText = "select picture from student where studentid=" + studentid;
OleDbCommand com = new OleDbCommand(cmdText, Untily.DBConnection);
OleDbDataReader reader = com.ExecuteReader();
byte[] ss = null;
if (reader.Read())
{
ss = (byte[])reader["picture"];
}
reader.Close();
Untily.DBClose();
if (ss != null)
{
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(ss);
}
}
}
........