zoukankan      html  css  js  c++  java
  • 读取二进制大对象

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.IO;
    using System.Data.SqlClient;
    
    namespace main
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void btnUpload_Click(object sender, EventArgs e)
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = "*.jpg|*.jpg|*.png|*.png|*.bmp|*.bmp";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    string fileName = ofd.FileName;
                    FileStream fs = new FileStream(fileName, FileMode.Open);
                    byte[] imageBytes = new byte[fs.Length];
                    BinaryReader br = new BinaryReader(fs);
                    imageBytes = br.ReadBytes(Convert.ToInt32(fs.Length));
    
                    string s = "server=PC-20171113RBMO;database=StudentDB;Trusted_Connection=true";
                    SqlConnection con = new SqlConnection(s);
    
                    string c = "insert into Pic(image) values(@pic)";
                    SqlCommand cmd = new SqlCommand(c, con);
                    SqlParameter para = new SqlParameter("@pic", SqlDbType.Image);
                    para.Value = imageBytes;
                    cmd.Parameters.Add(para);
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
            }
    
            private void btnRead_Click(object sender, EventArgs e)
            {
                string s = "server=PC-20171113RBMO;database=StudentDB;Trusted_Connection=true";
                SqlConnection con = new SqlConnection(s);
                string c = "select image from Pic where ID = " + textBox1.Text.Trim();
                SqlCommand cmd = new SqlCommand(c, con);
                con.Open();
                byte[] image = (byte[])cmd.ExecuteScalar();
                con.Close();
    
                MemoryStream ms = new MemoryStream(image);
                Bitmap bmp = new Bitmap(ms);
                pictureBox1.Image = bmp;
            }
        }
    }
  • 相关阅读:
    BZOJ 1002 轮状病毒
    poj_1952最大下降子序列,统计个数
    poj_3468线段树成段更新求区间和
    hdu_4707
    uva_644暴力加字典树解法
    正则表达式:处理文本内容中特定的字符串
    grep:文本搜索工具
    分析文本的工具:wc,sort,uniq,diff和patch
    按列抽取文本cut和合并文件paste
    显示文本前或后行内容:head,tail
  • 原文地址:https://www.cnblogs.com/zhang1997/p/8026473.html
Copyright © 2011-2022 走看看