0

我正在asp.net使用 oracle 数据库。我想打印保存在旧表中的员工图像。我什至没有保存在该表的照片字段中的图像数据类型。

我使用图像处理程序从新创建的表中打印图像,但是当我在旧表上查询时,图像没有被打印出来。

我怎么知道表格中是否保存了任何图像?

如果有图像为什么它没有被打印?

我将向您展示两个表(新、旧)的图像处理程序代码 新创建的表中的图像打印得非常好,但旧表的问题是什么。

任何人都可以给我任何建议吗?

这是我的ImgHandler.ashx代码;

 public void ProcessRequest (HttpContext context)
    {
        OracleDataReader rdr = null;
        OracleConnection conn = Conn.getConn();
        OracleCommand cmd = null;
        string ImgType = context.Request.QueryString["typ"].ToString();
        try
        {
            if (ImgType=="edu")//this is working fine
            {
                cmd = new OracleCommand("select attachment pic from newtbl where lvldcp_code=" + context.Request.QueryString["dcp"] + "and emp_code="+context.Request.QueryString["emp"], conn);
            }
            else if (ImgType=="profile")
            {
                cmd = new OracleCommand("select photo pic from oldtbl where emp_code="+context.Request.QueryString["emp"], conn);
            }

            conn.Open();
            rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                context.Response.ContentType = "image/jpg";
                context.Response.BinaryWrite((byte[])rdr["pic"]);
            }
            if (rdr != null)
                rdr.Close();
        }
        catch (Exception ex)
        {

        }
        finally
        {
            if (conn != null)
                conn.Close();
        }


    }
4

1 回答 1

0

如果您的查询返回一个 blob 字段值,那么您可以使用 OracleBlob 类。

public void ProcessRequest (HttpContext context)
{
    OracleDataReader rdr = null;
    OracleConnection conn = Conn.getConn();
    OracleCommand cmd = null;
    string ImgType = context.Request.QueryString["typ"].ToString();
    try
    {
        if (ImgType=="edu")//this is working fine
        {
            cmd = new OracleCommand("select attachment pic from newtbl where lvldcp_code=" + context.Request.QueryString["dcp"] + "and emp_code="+context.Request.QueryString["emp"], conn);
        }
        else if (ImgType=="profile")
        {
            cmd = new OracleCommand("select photo pic from oldtbl where emp_code="+context.Request.QueryString["emp"], conn);
        }

        Byte[] byteArray = null;
        OracleBlob blob;
        conn.Open();
        rdr = cmd.ExecuteReader();
        while (rdr.Read())
        {
            blob = rdr.GetOracleBlob(0);
            byteArray = new Byte[blob.Length];
            int i = blob.Read(byteArray, 0, System.Convert.ToInt32(blob.Length));

            //clob.Length or i > 0 will show if there are bites in the clob or not
        }
        if (rdr != null)
            rdr.Close();

        context.Response.ContentType = "image/jpg";
        context.Response.BinaryWrite(byteArray);
    }
    catch (Exception ex)
    {

    }
    finally
    {
        if (conn != null)
            conn.Close();
    }

}
于 2016-05-27T06:22:23.360 回答