- 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");
- 然后对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-------
Oracle的日志挖掘检查及升级Oracle数据库补丁版本相关资讯 Oracle教程
- Oracle中纯数字的varchar2类型和 (07/29/2015 07:20:43)
- Oracle教程:Oracle中查看DBLink密 (07/29/2015 07:16:55)
- [Oracle] SQL*Loader 详细使用教程 (08/11/2013 21:30:36)
| - Oracle教程:Oracle中kill死锁进程 (07/29/2015 07:18:28)
- Oracle教程:ORA-25153 临时表空间 (07/29/2015 07:13:37)
- Oracle教程之管理安全和资源 (04/08/2013 11:39:32)
|
本文评论 查看全部评论 (0)