Inserting blob using ORACLE OLEDB

G

Goku

Hi,

Iam trying to insert oracle blob using oracle oledb
driver. This seems to produce some error when embedding
the variable name using ? in the sql statement.

Could you please let me know. how to do this.

Regards
Goku
 
G

Goku Moorthy

Hi there,

string SQL = "INSERT INTO DOC_TEMPLATE_MST " +
"(DOCUMENTID,DOCUMENT_SOURCE) " + "VALUES(1,?)";

Cmd.Connection = db.GetOracleOleDBConnection();
Cmd.CommandType = CommandType.Text;
Cmd.CommandText = SQL ;


System.IO.FileStream fs = new System.IO.FileStream("D:\\test.txt",
System.IO.FileMode.Open,System.IO.FileAccess.Read);

//Create a byte array of file stream length
doc = new byte[fs.Length];

/Read block of bytes from stream into the byte array
fs.Read(doc,0,System.Convert.ToInt32(fs.Length));
//Close the File Stream
fs.Close();

Cmd.Parameters.Add( new
OleDbParameter("DOCUMENT_SOURCE",OleDbType.LongVarBinary));
Cmd.Parameters["DOCUMENT_SOURCE"].Direction =
ParameterDirection.Input;
Cmd.Parameters["DOCUMENT_SOURCE"].Value = doc;

Cmd.ExecuteNonQuery();


This GetOracleOleDBConnection function uses the following to get the
connection..

value="Provider=OraOLEDB.Oracle.1;User ID=test;Password=test;Data
Source=mainDB;OLEDB.NET=true;SPPrmsLOB=True;NDatatype=True;"

Please help...I am struck with it totally..!!
 
M

Miha Markic

Hi,

I've tried the following on Oracle 9ir2
OleDbCommand cmd = new OleDbCommand("INSERT INTO TUBO (ID, TEST) VALUES(2,
?)", oleDbConnection1);

cmd.Parameters.Add("TEST", OleDbType.LongVarBinary).Value = new byte[]{1, 2,
3};

oleDbConnection1.Open();

try

{

cmd.ExecuteNonQuery();

}

finally

{

oleDbConnection1.Close();

}

And it works just fine. What is the error you are getting?

You might also try using managed Oracle provider.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top