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




     

  • 相关阅读:
    hdu-2841 Visible Trees---容斥定理
    hdu-4135 Co-prime---容斥定理经典&&求1-m中与n互质的数目
    hdu-1796 How many integers can you find---容斥定理
    hdu-2837 Calculation---指数循环节
    FZU-1759 Super A^B mod C---欧拉降幂&指数循环节
    指数循环节&欧拉降幂
    hdu-3074 Multiply game---线段树+单点更新
    hdu-1792 A New Change Problem---数论&剩余系
    POJ-2429 GCD & LCM Inverse---给出gcd和lcm求原来两个数
    hdu-2685 I won't tell you this is about number theory---gcd和快速幂的性质
  • 原文地址:https://www.cnblogs.com/calmzeal/p/379109.html
Copyright © 2011-2022 走看看