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();
        }
    }

  • 相关阅读:
    深入理解浏览器的缓存机制
    【ES6】Set、Map、WeakSet 和 WeakMap 的区别
    js的防抖(debounce) 和 节流(throttling)
    git对比两个分支的差异——git checkout
    纯CSS实现可自定义间距虚线边框
    无语,非也
    Spring AOP
    Spring集成Junit
    Spring注解开发-新注解
    Spring注解开发-原始注解
  • 原文地址:https://www.cnblogs.com/handboy/p/7141610.html
Copyright © 2011-2022 走看看