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

  • 相关阅读:
    给域名添加解析
    MATLAB c/c++调用matlab<dll>
    MATLAB 矩阵生成有向网络图
    MATLAB 矩阵生成无向网络图
    MATLAB RGB2YCbCr、YCbCr2RGB
    MATLAB RGB2YUV、YUV2RGB
    MATLAB 直方图匹配
    MATLAB 双边滤波
    MATLAB 区域填充算法,队列版
    MATLAB 二值图像连通区域标记法,两步法
  • 原文地址:https://www.cnblogs.com/handboy/p/7141610.html
Copyright © 2011-2022 走看看