@manhng

Welcome to my blog!

BLOB

January 20, 2022 11:33

BLOB (edit)

Oracle Types:

  • BLOB
  • CLOB
  • BFILE

Oracle BLOB OOP:

  • Namespace: Oracle.DataAccess.Client
  • Assembly: Oracle.DataAccess.dll
  • System.Object
  • System.OracleBulkCopy

Oracle LOBs - ADO.NET | Microsoft Docs

Reading and Writing BLOB Data to Microsoft SQL or Oracle Database - CodeProject (HAY HAY HAY)

Working with BLOB and CLOB Data (devart.com) (HAY HAY HAY)

Upload Files And Save In Oracle Database In Blob Format In ASP.NET (c-sharpcorner.com)

Read / Write BLOBs from / to Oracle using C# .NET DataSet and DataReader (akadia.com)

Save C# Image Object into Oracle BLOB (godo.dev)

Oracle Data Provider for .NET Types Classes

Insert blob in oracle database with C# - Stack Overflow

c# - Inserting large BLOB into Oracle database - Stack Overflow

c# - Retrieve image from Oracle DB - Stack Overflow

Insert /Retrieve an Image Into/ From a Blob Field in Oracle Database using C#.Net (c-sharpcorner.com)

[RESOLVED] Reading Oracle BLOB using C# and Saving File-VBForums

CREATE TABLE BlobStore
(
ID number,
BLOBFILE BLOB,
DESCRIPTION varchar2(100)
);

string sql = " select * from BlobStore ";
string strconn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (OracleConnection conn = new OracleConnection(strconn))
{
conn.Open();
using (OracleCommand cmd = new OracleCommand(sql, conn))
{
using (IDataReader dataReader = cmd.ExecuteReader())
{
while (dataReader.Read())
{
byte[] byteArray= (Byte[])dataReader["BLOBFILE"];
using (FileStream fs = new FileStream
(strfn, FileMode.CreateNew, FileAccess.Write))
{
fs.Write(byteArray, 0, byteArray.Length);
}
}
}
}
}

static void UploadBlob(OracleConnection connection) { // Open file on disk FileStream stream = new FileStream(@"D:\Tmp\test.bmp", FileMode.Open, FileAccess.Read); BinaryReader reader = new BinaryReader(stream); try { connection.Open(); // Create temporary BLOB OracleLob lob = new OracleLob(connection,OracleDbType.Blob); int streamLength = (int)stream.Length; // Transfer data to server lob.Write(reader.ReadBytes(streamLength), 0, streamLength); // Perform INSERT OracleCommand command = new OracleCommand( "INSERT INTO Pictures (ID, PicName, Picture) VALUES(1,'pict1',:Pictures)", connection); OracleParameter param = command.Parameters.Add("Pictures", OracleDbType.Blob); param.OracleValue = lob; Console.WriteLine(command.ExecuteNonQuery() + " rows affected."); } finally { connection.Close(); reader.Close(); stream.Close(); } } static void DownloadBlob(OracleConnection connection) { OracleCommand command = new OracleCommand("SELECT * FROM Pictures", connection); connection.Open(); OracleDataReader reader = command.ExecuteReader(System.Data.CommandBehavior.Default); try { while (reader.Read()) { // Obtain OracleLob directly from OracleDataReader OracleLob lob = reader.GetOracleLob("Picture"); if (!lob.IsNull) { string fileName = reader.GetString("PicName"); // Create file on disk FileStream stream = new FileStream(@"D:\Tmp\" + fileName + ".bmp", FileMode.Create); // Use buffer to transfer data byte[] buffer = new byte[lob.Length]; // Read data from database lob.Read(buffer,0,(int)lob.Length); // Write data to file stream.Write(buffer,0,(int)lob.Length); stream.Close(); Console.WriteLine(fileName + " downloaded."); } } } finally { reader.Close(); connection.Close(); } }

Categories

Recent posts