日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

oracle Blob保存方式,关于文件保存到Oracle中BLOB字段的方法及例子

發(fā)布時(shí)間:2024/9/27 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle Blob保存方式,关于文件保存到Oracle中BLOB字段的方法及例子 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

關(guān)于文件保存到Oracle中BLOB字段的方法及例子

-------------------------------------------

public class FileOpClass

{

public static byte[] GetFileStream(string filepath)

{

byte[] byteArray = null;

FileStream fs = null;

try

{

fs = new FileStream(filepath, FileMode.Open);

long filelength = fs.Length;

byteArray = new byte[filelength];

fs.Read(byteArray, 0, byteArray.Length);

}

catch (Exception ee)

{

}

finally

{

if (fs != null)

{

fs.Close();

fs.Dispose();

fs = null;

}

}

return byteArray;

}

public static void WriteToFile(byte[] byteArray, string filepath)

{

if (System.IO.File.Exists(filepath) == true)

{

try

{

System.IO.File.Delete(filepath);

}

catch { }

}

FileStream fs = null;

try

{

fs = new FileStream(filepath, FileMode.OpenOrCreate);

fs.Write(byteArray, 0, byteArray.Length);

fs.Flush();

}

catch (Exception ee)

{

}

finally

{

if (fs != null)

{

fs.Close();

fs.Dispose();

fs = null;

}

}

}

}

//------------------------------------------

先插入一條objblob字段為空的記錄,用insert into tablename(objid,objname) values('xxx','yyyy');

然后對(duì)objblog字段作update方式操作

//------------------------------------------

byte[] byteArray =FileOpClass.GetFileStream(path);

object UpdateBLOBFdValue=byteArray;

//------------------------------------------

//更新BLOB字段值的方法

//------------------------------------------

public bool UpdateBLOBFieldValue(string UpdateTableName, string UpdateBLOBFieldName, object UpdateBLOBFdValue, string WhereEqFieldName, string WhereEqFdValue)

{

bool rbc = false;

DatabaseHelperClass dbh = new DatabaseHelperClass(m_Database);

DbConnection dbconn = null;

DbTransaction dbtrans = null; //Provider=OraOleDb.Oracle;

DbCommand dbCmd1 = null;

try

{

dbconn = dbh.db.CreateConnection();

if (dbconn.State != ConnectionState.Open)

{

dbconn.Open();

}

dbtrans = dbconn.BeginTransaction();

string PrixChar = dbh.PrixChar;

string x = "update " + UpdateTableName + " set " + UpdateBLOBFieldName + "=" + PrixChar + "Img where " + WhereEqFieldName + "=" + PrixChar + "tmpguid ";

byte[] byteArray = UpdateBLOBFdValue as byte[];

//

dbCmd1 = dbconn.CreateCommand();

dbCmd1.CommandText = x;

dbCmd1.CommandType = CommandType.Text;

dbCmd1.Connection = dbconn;

dbCmd1.Transaction = dbtrans;

//

DbParameter dbparam = dbh.CreateParameter("" + PrixChar + "Img", byteArray);

dbparam.Direction = ParameterDirection.Input;

dbparam.DbType = System.Data.DbType.Binary;

dbparam.Value = byteArray;

dbCmd1.Parameters.Add(dbparam);

dbCmd1.Parameters.Add(dbh.CreateParameter("" + PrixChar + "tmpguid", WhereEqFdValue));

if (dbCmd1.ExecuteNonQuery() > 0)

{

rbc = true;

dbtrans.Commit();

}

}

catch (Exception ee)

{

if (dbtrans != null)

{

dbtrans.Rollback();

}

rbc = false;

}

finally

{

if (dbCmd1 != null)

{

dbCmd1.Dispose();

dbCmd1 = null;

}

//----

if (dbtrans != null)

{

dbtrans.Dispose();

dbtrans = null;

}

if (dbconn != null)

{

dbconn.Dispose();

dbconn = null;

}

}

return rbc;

}

----the---end-------

總結(jié)

以上是生活随笔為你收集整理的oracle Blob保存方式,关于文件保存到Oracle中BLOB字段的方法及例子的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。