Rendering bytes from sql server to an image control?

后端 未结 4 688
天涯浪人
天涯浪人 2020-12-22 04:20

Markup:


    
        
4条回答
  •  一生所求
    2020-12-22 05:13

    See full article here.

    public class NWEmpPhotoHandler : IHttpHandler 
    { 
        public bool IsReusable { get { return true; } } 
    
        public void ProcessRequest(HttpContext ctx) 
        { 
            string id = ctx.Request.QueryString["id"]; 
    
            SqlConnection con = new SqlConnection(<>); 
            SqlCommand cmd = new SqlCommand("SELECT Photo FROM Employees WHERE EmployeeID = @EmpID", con); 
            cmd.CommandType = CommandType.Text; 
            cmd.Parameters.Add("@EmpID", id); 
    
            con.Open(); 
            byte[] pict = (byte[])cmd.ExecuteScalar(); 
            con.Close(); 
    
            ctx.Response.ContentType = "image/bmp"; 
            ctx.Response.OutputStream.Write(pict, 78, pict.Length - 78); 
        } 
    } 
    

提交回复
热议问题