zoukankan      html  css  js  c++  java
  • 存读Blob Oracle

    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.Data.OracleClient;
    using System.IO;

    namespace TestOraclBlob
    {
        public partial class Form1 : Form
        {
            OracleConnection conn;
            public Form1()
            {
                InitializeComponent();
                string strCon = "Data Source=orcl;Persist Security Info=True;User ID=wcq;Password=wcq123;Unicode=True;";
                conn = new OracleConnection(strCon);
            }
            //写入数据库
            private void button1_Click(object sender, EventArgs e)
            {
                OracleCommand cmd = new OracleCommand("", conn);

                string path = @"C:UserslenovoDesktop1.pdf";
                FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
                Byte[] fsByte = new byte[fs.Length]; //把图片转成 Byte型 二进制流  
                fs.Read(fsByte, 0, fsByte.Length);   //把二进制流读入缓冲区   
                fs.Close();

                cmd.CommandText = "insert into Student(id,name,storeblob) values(1,'aa',:zp)";
                cmd.Parameters.Add(":zp", OracleType.BFile, fsByte.Length);
                cmd.Parameters[0].Value = fsByte;

                conn.Open();
                cmd.ExecuteNonQuery();

                MessageBox.Show("插入成功!");
                conn.Close();
            }

            private void button2_Click(object sender, EventArgs e)
            {
                string path = @"C:UserslenovoDesktop2.pdf";

                DataTable dt = new DataTable();
                OracleDataAdapter adapter = new OracleDataAdapter("select storeBlob from student", conn);

                adapter.Fill(dt);
                Byte[] filebyte = (byte[])(dt.Rows[1][0]);

                FileStream fs = new FileStream(path, FileMode.Create);


                fs.Write(filebyte, 0, filebyte.GetLength(0));

                fs.Close();

                MessageBox.Show("读取成功!");
            }
        }

    }

  • 相关阅读:
    做了48小时爸爸的感觉!
    利用Session和HashTable制作购物车
    vs2005控件演示之 Literal
    vs2005/.net2.0 控件实例之 下拉列表《DropDownList》
    vs2005/.net2.0 控件实例之 单选按纽和复选框 <RadioButton><CheckBox>
    vs2005/.net2.0 控件实例之 单选列表和复选列表
    一个被大多数初级程序员忽略的安全问题 [严重]
    使用Northwind和Entity框架的ASP.NET MVC实例发布
    对话Spring.NET
    揭开HTML 5工作草稿的神秘面纱
  • 原文地址:https://www.cnblogs.com/wangcq/p/3778404.html
Copyright © 2011-2022 走看看