zoukankan      html  css  js  c++  java
  • C#中通过OleDb操作Oracle Blob数据类型

    使用数据源为System.Data.Oledb,Provider为Oracle Provider For .Net
    没用OracleClient,因为这个只能用在Oracle
    Provider要改为Oracle Proider form Net,默认的MS Oledb For Oracle不支持高版本Oracle(8.0以上)
    ConnectionString如下:
    Provider=OraOLEDB.Oracle.1;Password=“”;Persist Security Info=True;User ID=“”;Data Source=“”

    获取Lob数据
    DataAdpter.Fill(DataSet);
    通过DataType判断为Lob后
    强制转化该列为byte[]

    if ( ds.Tables["tAttrFile"].Columns[sFieldName].DataType == typeof(System.Byte[]))
                            
    {
                                
    byte[] MyData= (byte[]) ds.Tables["tAttrFile"].Rows[j][sFieldName];
                                
    int ArraySize = new int();
                                ArraySize 
    = MyData.GetUpperBound(0);

                                FileStream fs 
    = new FileStream(sTempFileName,FileMode.OpenOrCreate, FileAccess.Write);
                                fs.Write(MyData, 
    0,ArraySize + 1);
                                fs.Close();
                            }
                                                    


    插入、修改Lob数据
    使用Command的Parameters,类型为Binary

    byte[] data = cs.Base64DecodeEx(sData);

                    cmd[
    0= new System.Data.OleDb.OleDbCommand();
                    cmd[
    0].CommandText = "delete from " + sTableName + " where sProjID='" + sProjID +
                        
    "' and iDegree=" + iDegree.ToString();
                
                    cmd[
    1= new System.Data.OleDb.OleDbCommand();
                    cmd[
    1].CommandText = "insert into " + sTableName+" (sProjID,iDegree,"  + sFieldName + ") values ('" + 
                        sProjID 
    + "',"+ iDegree.ToString() + ",:bData)";
                    cmd[
    1].Parameters.Add("bData",System.Data.OleDb.OleDbType.Binary,data.Length);
                    cmd[
    1].Parameters["bData"].Value = data;
                    iResult 
    = db.ExecuteSqls(cmd,2);    




     

  • 相关阅读:
    为什么 Linux Mint 比 Ubuntu好?
    未将对象引用设置到对象的实例--可能出现的问题总结
    Java的位运算符具体解释实例——与(&)、非(~)、或(|)、异或(^)
    openldap---ldapsearch使用
    HDU1342 Lotto 【深搜】
    XMPP协议的原理介绍
    百度究竟是哪国的公司
    DWZ使用笔记
    利用Excel批量高速发送电子邮件
    文法分析
  • 原文地址:https://www.cnblogs.com/calmzeal/p/379109.html
Copyright © 2011-2022 走看看