Read oracle blob data through ODBC connection ADO.net
Hi,
How to read blob data in Oracle database using ODBC connection in ADO.NET(c#). I'm using Oracle 10g .
I have tried the following code but i couldn't succeed. If you know where i'm doing mistake means guide me.
Whether my SelectQuery is correct.
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Odbc;
using System.IO;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
using System.Data.SqlClient;
using System.Data.SqlTypes;
namespace Blob
{
class Program
{
static void Main(string[] args)
{
try
string constr = "DSN=Test;Server=ORCL;UId=scott;Pwd=tiger;Driver={Microsoft ODBC for Oracle};";
OdbcConnection oCon = new OdbcConnection(constr);
oCon.Open();
string SelectQuery = "SELECT content from PS_TXN WHERE id = 75; ";
OdbcCommand oCmd = new OdbcCommand();
oCmd.Connection = oCon;
oCmd.CommandText = SelectQuery;
oCmd.CommandType = System.Data.CommandType.Text;
OdbcParameter odbcReadParam = new OdbcParameter("blobfromdb",OdbcType.Image ) ;
odbcReadParam.Direction = System.Data.ParameterDirection.Output;
oCmd.Parameters.Add(odbcReadParam);
odbcReadParam.SourceColumn = "Content";
byte[] byteData = new byte[0];
object obj = oCmd.Parameters[0].Value; //this value always shows null
if (obj != null)
{
Console.ReadLine();
int ArraySize = new int();
ArraySize = byteData.GetUpperBound(0);
FileStream fs1 = new FileStream(@"e:\Vinoth\airport-tunnel-blur.jpg",
FileMode.OpenOrCreate, FileAccess.Write); fs1.Write(byteData, 0, ArraySize);
fs1.Close();
Console.ReadLine();
}
}
catch (OracleException e){
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
}
}
Please help me to find solution.
Regards,
Vinoth