DEVELOPER: ODP.NET Serving Winning LOBs:

http://www.oracle.com/technetwork/issue-archive/2005/05-nov/o65odpnet-085139.html

Data Provider for .NET Developer's Guide:

https://docs.oracle.com/database/121/ODPNT/OracleBlobClass.htm#ODPNT4035

从blob字段读取一个图片文件的代码:

        OracleConnection con = new OracleConnection(connStr);
con.Open(); // statement to get a blob
string sql = "select yz from sysusers where yhdh='123'"; // create command object
// InitialLOBFetchSize
// defaults to 0
OracleCommand cmd = new OracleCommand(sql, con); // create a datareader
using (OracleDataReader dr = cmd.ExecuteReader())
{
// read the single row result
dr.Read();
// use typed accessor to retrieve the blob
OracleBlob blob = dr.GetOracleBlob(); // create a memory stream from the blob
using (MemoryStream ms = new MemoryStream(blob.Value))
{
// set the image property equal to a bitmap
// created from the memory stream
pictureBox1.Image = new Bitmap(ms);
}
}

保存文件到blob字段的代码:

         con.Open();

         // 利用事务处理(必须)
OracleTransaction transaction = con.BeginTransaction();
string sql="select yz from sysusers where yhdh='123' FOR UPDATE";
OracleCommand cmd = new OracleCommand(sql, con); using ( OracleDataReader reader = cmd.ExecuteReader())
{
//Obtain the first row of data.
reader.Read();
//Obtain a LOB.
OracleBlob blob = reader.GetOracleBlob();
blob.Erase();
// 将文件写入 BLOB 中
byte[] Buffer;
FileStream fs = new FileStream(@"d:\01.jpg", FileMode.Open);
using (MemoryStream ms = new MemoryStream())
{
int b;
while ((b = fs.ReadByte()) != -)
{
ms.WriteByte((byte)b);
}
Buffer = ms.ToArray();
} // Begin ChunkWrite to improve performance
// Index updates occur only once after EndChunkWrite
blob.Position=;
blob.BeginChunkWrite(); //启用BeginChunkWrite不是必须,只与性能有关
blob.Write(Buffer, ,Buffer .Length); //从字节数据写入blob字段
blob.EndChunkWrite();
blob.Close();
}
// 提交事务
transaction.Commit();
con.Close();

最新文章

  1. 使用caffe时遇到的问题
  2. Bzoj1115 石子游戏Kam
  3. python二维数组
  4. [LeetCode]题解(python):082 - Remove Duplicates from Sorted List II
  5. Oracle目录结构及创建新数据库
  6. MongoDB 的创建、查询、更新、删除
  7. vijosP1159 岳麓山上打水
  8. thinkphp如何写find_in_set这样的orm查询封装
  9. Asp.net Mvc 第二回 UrlRouting
  10. SSDT表详解
  11. iOS 用UISearchDisplayController实现查找功能
  12. kafka服务安装-SuSE Linux Enterprise Server 11 SP3
  13. 1599: [Usaco2008 Oct]笨重的石子
  14. 深入理解JavaScript的this指向问题
  15. Linux - 系统信息相关命令
  16. 5. Go函数
  17. 《Java程序设计》第二周学习记录(2)
  18. 整理this笔记
  19. concurrent.futures模块(进程池/线程池)
  20. ftrace利器之trace-cmd和kernelshark

热门文章

  1. Linux段式管理与页式管理
  2. 493. Reverse Pairs
  3. C# 控件置于最顶层、最底层、隐藏、显示
  4. Kings(状压DP)
  5. J2EE中getParameter与getAttribute以及对应的EL表达式
  6. SpringBoot推荐基础包
  7. unbantu安装wmvare
  8. 用 Flask 来写个轻博客
  9. javascript类式继承模式#2——借用构造函数
  10. 《Cracking the Coding Interview》——第16章:线程与锁——题目1