添加一个名为showImg.aspx文件,前台无需设计,仅需在后台添加以下代码
protected void Page_Load(object sender, EventArgs e)
{
string id = Request.QueryString["id"].ToString(); //获取id
string connstr = "Data Source=WUXSG01\\SQLEXPRESS;uid=sa;pwd=test;DataBase=test1"; //连接数据库
SqlConnection connection = new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand("select photo from test1 where id= '" + id + "'", connection);//查询
connection.Open();
byte[] imageData = (byte[])cmd.ExecuteScalar();//转换
connection.Close();
Response.OutputStream.Write(imageData, 0, imageData.Length);//输出
}
如果要显示,则
Image1.ImageUrl = "ShowImg.aspx?id=" + id;