我需要使用 C# 在 ASP 页面中使用 ODBC 连接将存储在 mysql db 中的图像显示为 blob 字段。请帮我
<%@ WebHandler Language="C#" Class="stdImg" %>
使用系统;使用 System.Web;
公共类 stdImg : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
System.Data.Odbc.OdbcConnection con = new System.Data.Odbc.OdbcConnection();
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["sis"].ConnectionString;
con.Open();
System.Data.Odbc.OdbcCommand cmd = con.CreateCommand();
cmd.CommandText = "SELECT PHOTOGRAPH FROM student_mast WHERE ADMISSION_NO='1000000001'";
byte[] buf = (byte[])cmd.ExecuteScalar();
context.Response.Clear();
context.Response.OutputStream.Write(buf, 0, buf.Length);
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite(buf);
}
public bool IsReusable
{
get
{
return false;
}
}
}