zoukankan      html  css  js  c++  java
  • net9:图片文件转换成二进制流存入SQL数据库,以及从数据库中读取二进制流输出文件

    原文发布时间为:2008-08-10 —— 来源于本人的百度文章 [由搬家工具导入]

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;


    using System.Data.SqlClient;

    public partial class Default4 : System.Web.UI.Page
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["imgDataConn"].ConnectionString);
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Guid gid = Guid.NewGuid();
            conn.Open();
            SqlCommand cmd = new SqlCommand("Insert into imgdata(gid,filedata) values(@gid,@filedata)", conn);
            cmd.Parameters.Add("@gid", SqlDbType.UniqueIdentifier).Value = gid;
            cmd.Parameters.Add("@filedata",SqlDbType.Image).Value=FileUpload1.FileBytes;
            cmd.ExecuteNonQuery();
            conn.Close();

            Session["gid"]=gid;
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand("Select filedata from imgdata where gid='" + Session["gid"].ToString() + "'", conn);
            byte[] fbt = (byte[])cmd.ExecuteScalar();
            conn.Close();
            Response.OutputStream.Write(fbt, 0, fbt.Length);
            Response.End();
        }
    }

  • 相关阅读:
    移动硬盘加密方法赏析
    Windows7下怎么对文件或者文件夹进行EFS加密
    win7怎么设置电脑自动关机
    电脑定时关机怎么设置
    用vb编程给u盘加密
    中医课件集合
    在手机上查询药品信息?PEP移动掌上药物信息参考
    【好站收藏】六脉医学资料下载网sixmed.cn
    百度进军C2C叫板淘宝电子商务领域竞争升级
    IBM 笔记本T43键盘帽安装手记
  • 原文地址:https://www.cnblogs.com/handboy/p/7141610.html
Copyright © 2011-2022 走看看