• .net 将数据库二进制图片在image中展示


    关键代码

                    int iLeft = (j % 3) * 360;
    
                    string strLeft = iLeft.ToString();
    
                    int iLeft0 = iLeft + 10;
                    string strLeft0 = iLeft0.ToString();
                    string  HImage ="70";
    
                    int iTop = row * 70;
                    int iTopImage = iTop - 20;
                    string strTop = iTop.ToString();
                    string strTopImage = iTopImage.ToString();
    
                    Image image = new Image();
                    image.ImageUrl = "Common/ShowImage.aspx?id=" + dt.Rows[i][3].ToString(); //获取签名
                    image.CssClass = "tmd";
                    image.Style.Add(HtmlTextWriterStyle.Left, iLeft0 + "px");
                    image.Style.Add(HtmlTextWriterStyle.Top, strTopImage + "px");
                    image.Style.Add(HtmlTextWriterStyle.Height, HImage + "px");
    
                    this.Controls.Add(image);
                    

    ShowImage.aspx

    using System;
    using System.Data.OracleClient;
    using System.Web.UI;
    
    public partial class NewFrameWorkUI_Physician_Common_ShowImage : System.Web.UI.Page
    {
        string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringOracle10"].ToString();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ShowData();
            }
        }
        public void ShowData()
        {
            object s = Request.QueryString["id"];     
            string strSQL = "select emp_no,name,signature from staff_dict where id='" + s.ToString() + "'";
            OracleConnection connection = new OracleConnection(connectionString);
            OracleCommand cmd = new OracleCommand(strSQL, connection);
            try
            {
                connection.Open();
                OracleDataReader myReader = cmd.ExecuteReader();
                if (myReader.Read())
                {
                    if (myReader["signature"] is DBNull)
                        return;
                    Response.Clear();
                    Response.ContentType = "application/binary;";
                    Response.BinaryWrite((byte[])myReader["signature"]);
    
                    Response.Flush();
                    Response.End();
                }
            }
            catch (System.Data.OracleClient.OracleException E)
            {
                throw new Exception(E.Message);
            }
        }
    }
  • 相关阅读:
    替换URL传递的参数
    执行SQl语句得到xml结果集
    table中文本太长换行
    org.xml.sax.SAXNotRecognizedException
    WAMP+CMSeasy快速搭建学校网站
    推荐几个web前台开发的小工具
    来园子里注册啦
    C++ Virtual的背后
    Games101观后补充笔记
    Lua语法入门
  • 原文地址:https://www.cnblogs.com/chenpanpan/p/14431668.html
Copyright © 2020-2023  润新知