使用数据源为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();
}
{
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 );
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 );