using (SqlConnection conn = new SqlConnection(connStrdg1))
{
conn.Open();
string strSQL = "";
using (SqlCommand command = new SqlCommand())
{
command.Connection = conn;
command.CommandType = CommandType.Text;
strSQL = "SELECT image FROM XXXX WHERE id=@imgid";
command.CommandText = strSQL;
command.Parameters.Add("imgid", SqlDbType.UniqueIdentifier).Value = new Guid(Request.QueryString["imgid"].ToString());
//下面這句為主要關鍵所在
Response.ContentType = "image/jpeg";
byte[] image = (byte[])command.ExecuteScalar();
if (image == null)
{
Response.Redirect("/NoImage.gif");
}
else
{
Response.BinaryWrite(image);
}
}
}
留言
張貼留言
您好,我是 Lawrence,這裡是我的開發筆記的網誌,如果你對我的文章有任何疑問或者有錯誤的話,歡迎留言讓我知道。