public void ProcessRequest(HttpContext context)
{
MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString.ToString());
// Create SQL Command
int adid= int.Parse(context.Request.QueryString["adid"]);
int imgid = int.Parse(context.Request.QueryString["imgid"]);
MySqlCommand cmd = new MySqlCommand();
//cmd.CommandText = "Select i.image_id, i.image_name, i.image_byteImage, i.image_adId from images i,postadverties p where i.image_adId =@ID";
cmd.CommandText = "SELECT image_id,image_byteImage FROM images WHERE image_adId="+ adid + " and image_id="+ imgid;
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
//MySqlParameter AdId = new MySqlParameter("@ID", MySqlDbType.Int32);
//MySqlParameter imgid = new MySqlParameter("@imgid", MySqlDbType.Int32);
//AdId.Value =
//imgid.Value =
//cmd.Parameters.Add(AdId);
//cmd.Parameters.Add(imgid);
con.Open();
MySqlDataReader dReader = cmd.ExecuteReader();
if (dReader.Read())
{
byte[] binaryimg = (byte[])dReader["image_byteImage"];
string base64string = "data:image/jpeg;base64," + Convert.ToBase64String(binaryimg);
context.Response.Write(base64string);
context.Response.Flush();
context.Response.End();
}
dReader.Close();
con.Close();
}
Click here to see result 当试图显示存储在数据库中的图像时,显示结果而不是图像。不知道为什么会出现这个问题。在转换它或其他一些时有任何问题。在另一个页面它可以工作,在某些页面上它没有。