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[]

None.gif if  ( ds.Tables[ " tAttrFile " ].Columns[sFieldName].DataType  ==   typeof (System.Byte[]))
ExpandedBlockStart.gifContractedBlock.gif                        
dot.gif {
InBlock.gif                            
byte[] MyData= (byte[]) ds.Tables["tAttrFile"].Rows[j][sFieldName];
InBlock.gif                            
int ArraySize = new int();
InBlock.gif                            ArraySize 
= MyData.GetUpperBound(0);
InBlock.gif
InBlock.gif                            FileStream fs 
= new FileStream(sTempFileName,FileMode.OpenOrCreate, FileAccess.Write);
InBlock.gif                            fs.Write(MyData, 
0,ArraySize + 1);
InBlock.gif                            fs.Close();
ExpandedBlockEnd.gif                        }
                                                


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

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




 

转载于:https://www.cnblogs.com/calmzeal/archive/2006/04/19/379109.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值