zoukankan      html  css  js  c++  java
  • 向oracle 数据库写入 LOBs 数据

    create or replace procedure UpdatePhoto(v_id in integer,v_binaryPhoto in blob) is
    begin
      update usersinfo u set u.photo=v_binaryPhoto where u.id=v_id;
    end UpdatePhoto;

    /

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;

    namespace winformOracleDemo
    {
        public partial class BlobAndBFiles : Form
        {
            public BlobAndBFiles()
            {
                InitializeComponent();
            }

            private void BlobAndBFiles_Load(object sender, EventArgs e)
            {

            }

            private void BtnUpLoad_Click(object sender, EventArgs e)
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    textBox1.Text = openFileDialog1.FileName;

                    byte[] bytePhoto = System.IO.File.ReadAllBytes(openFileDialog1.FileName);

                    try
                    {
                        using (OracleConnection conn = new OracleConnection(BusinessTools.ConnectionString))
                        {
                            conn.Open();

                       
                            OracleCommand cmd = conn.CreateCommand();
                            cmd.CommandText = "UpdatePhoto";
                            cmd.CommandType = CommandType.StoredProcedure;

                            OracleParameter paraId = new OracleParameter();
                            paraId.ParameterName = "v_id";
                            paraId.OracleDbType = OracleDbType.Int32;
                            paraId.Direction = ParameterDirection.Input;
                            paraId.Value = Convert.ToInt32(txtUserID.Text.Trim());
                            cmd.Parameters.Add(paraId);

                            OracleBlob orclBlob = new OracleBlob(conn);
                            orclBlob.Write(bytePhoto, 0, bytePhoto.Length);

                            OracleParameter paraPhoto = new OracleParameter();
                            paraPhoto.ParameterName = "v_binaryPhoto";
                            paraPhoto.OracleDbType = OracleDbType.Blob;
                            paraPhoto.Value = orclBlob;
                            paraPhoto.Direction = ParameterDirection.Input;                     

                            cmd.Parameters.Add(paraPhoto);

                            cmd.ExecuteNonQuery();
                        
                        }
                    }
                    catch (Exception ex)
                    {
                        string ss = ex.Message;
                    }
                }
            }


        }
    }

  • 相关阅读:
    2013年4月20日
    关于"退耦"
    关于PCB原理图中的FBFB是磁珠的符号电子元器件电路图
    搜索技巧总结
    收集 QQ旋风离线下载帐号
    转载一篇日志
    硬件原理图和实物对比理解_EM310模块电路
    硬件原理图和实物对比理解_zigbee模块
    硬件原理图和实物对比理解_LPC电源模块
    word无法读取此文件,文档可能已损坏_可能的补救方法
  • 原文地址:https://www.cnblogs.com/kingwangzhen/p/1795274.html
Copyright © 2011-2022 走看看