Page 1 of 1
ExecuteArray with Stream object
Posted: Mon 10 Oct 2011 19:03
by eekstein
I am using the ExecuteArray and have a class that is a subclass of a Stream. The class also implements IConvertible. I implemented the GetTypeCode method to return TypeCode.Object. Then I implemented the ToType method to return a byte array of the Stream. The ExecuteArray does call the GetTypeCode method but does not seem to call the ToType method, instead I get an "Unknown type" error in OracleValue (I inspected it through Quick Watch).
I am adding the parameter as a type OracleDBType.Blob...
Code: Select all
command.Parameters.Add(
new OracleParameter("myImage", OracleDbType.Blob, ParameterDirection.Input)
{
Value = value
});
What is the appropriate way to include a Stream as a column in theExecuteArray?
Posted: Tue 18 Oct 2011 14:01
by Shalex
I cannot reproduce the problem with cmd.ExecuteArray() and OracleLobs using the code below. If it doesn't help, please
send us a small test project with the corresponding DDL/DML script to reproduce the issue in our environment.
Code: Select all
using (OracleConnection conn = new OracleConnection()) {
conn.ConnectionString = "server=orcl1120;uid=***;pwd=***;";
conn.Open();
FileStream fs = new FileStream("D:\Temp\foto.jpg", FileMode.Open, FileAccess.Read);
BinaryReader r = new BinaryReader(fs);
//Create temporary BLOB
OracleLob myLob = new OracleLob(conn, OracleDbType.Blob);
int streamLength = (int)fs.Length;
//Transfer data to server
myLob.Write(r.ReadBytes(streamLength), 0, streamLength);
OracleCommand cmd = conn.CreateCommand();
// Set command text property
cmd.CommandText = "INSERT INTO blob_table VALUES(:blobcolumn, :id)";
// Add parameters to command parameters collection
cmd.Parameters.Add("blobcolumn", OracleDbType.Blob);
cmd.Parameters.Add("id", OracleDbType.Integer);
// Set parameters values
cmd.Parameters["blobcolumn"].OracleValue = new OracleLob[] { myLob, myLob };
cmd.Parameters["id"].Value = new int[] { 1,2 };
// Insert two records at one time
cmd.ExecuteArray(2);
}
For more information, refer to
http://www.devart.com/dotconnect/oracle ... yBind.html
http://www.devart.com/dotconnect/oracle/docs/?Lob.html