Groups | Blog | Home
all groups > dotnet ado.net > september 2005 >

dotnet ado.net : Object must implement IConvertible, writing to BLOB


Jonaze
9/21/2005 4:46:03 AM
I have a function with the following code, I have written this function
with the example provided in the documentation provided with
OracleClient.

The called stored procedure functions perfectly, I have tested it
manually with success, but when I try to use the function, I get the
error "Object must implement IConvertible".

I also tested with the code in comment, without success and the same
result. If anyone has an idea...

int fileLength = Convert.ToInt32(_BinaryFile.Length);
byte[] fileBinary = new byte[fileLength];

int status = _BinaryFile.Read(fileBinary, 0, fileLength);

_BinaryFile.Close();

OracleConnection oc = new
OracleConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

oc.Open();
OracleTransaction tx = oc.BeginTransaction();
OracleCommand ocm = oc.CreateCommand ();
ocm.Transaction = tx;
/*

ocm.CommandText = "declare xx blob; begin dbms_lob.createtemporary(xx,
false, 0); :tempblob := xx; end;";
ocm.Parameters.Add(new OracleParameter("tempblob",
OracleType.Blob)).Direction = ParameterDirection.Output;
ocm.ExecuteNonQuery();

OracleLob ol = (OracleLob)ocm.Parameters[0].Value;

ol.BeginBatch(OracleLobOpenMode.ReadWrite);
ol.Write(fileBinary, 0, fileLength);
ol.EndBatch();
*/
ocm.Parameters.Clear();

ocm.CommandText = PUT_FILE; //Constant
ocm.CommandType = CommandType.StoredProcedure;

ocm.Parameters.Add( new OracleParameter("PROCESS_ID",
OracleType.VarChar, 36)).Value = _ProcessID;
ocm.Parameters.Add( new OracleParameter("NSB", OracleType.VarChar,
15)).Value = _NSB;
ocm.Parameters.Add( new OracleParameter("GENERATION_DATE",
OracleType.DateTime)).Value = _Date;
if (_AllPublication)
ocm.Parameters.Add( new OracleParameter("ALLPUBLICATION",
OracleType.Number)).Value = 1;
else
ocm.Parameters.Add( new OracleParameter("ALLPUBLICATION",
OracleType.Number)).Value = 0;
ocm.Parameters.Add( new OracleParameter("FILTERED",
OracleType.Number)).Value = _Filtered;
ocm.Parameters.Add( new OracleParameter("DATE_FROM",
OracleType.DateTime)).Value = _DateFrom;
ocm.Parameters.Add( new OracleParameter("DATE_TO",
OracleType.DateTime)).Value = _DateTo;
ocm.Parameters.Add( new OracleParameter("FILE_FORMAT",
OracleType.VarChar, 3)).Value = _Format;
ocm.Parameters.Add( new OracleParameter("PATH", OracleType.VarChar,
500)).Value = _Path;
ocm.Parameters.Add( new OracleParameter("FILE_NAME",
OracleType.VarChar, 500)).Value = _FileName;
ocm.Parameters.Add( new OracleParameter("FILE_BINARY",
OracleType.Blob)).Value = fileBinary;
//ocm.Parameters.Add( new OracleParameter("FILE_BINARY",
OracleType.Blob)).Value = ol;
ocm.Parameters.Add( new OracleParameter("p_err",
OracleType.Number)).Direction = ParameterDirection.Output;

ocm.ExecuteNonQuery();

tx.Commit();

oc.Close();
Sahil Malik [MVP]
9/21/2005 10:10:06 AM
The data type specified on the OracleParameter is incorrect.

--

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
----------------------------------------------------------------------------
---------------

[quoted text, click to view]

Jonaze
9/21/2005 11:51:14 AM
Sorry if I am stupid...

And which datatype I have to use ?
Into the Oracle procedure the column type is Blob and if you see the
example provided into MSDN and the Oracle documentation, they also use
blob.
Could you be more precise in your answer?

Thank you
Jo=EBl


Sahil Malik [MVP] a =E9crit :

[quoted text, click to view]
Sahil Malik [MVP]
9/21/2005 3:41:29 PM
Well, it's one of the parameters whose datatype is incorrect. You will have
to match up the database column data type to the OracleParameter.DbType
specified one by one .. sorry can't really tell much without actually
looking at your tables and have a working app in front of me.

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
----------------------------------------------------------------------------
---------------



[quoted text, click to view]
Sorry if I am stupid...

And which datatype I have to use ?
Into the Oracle procedure the column type is Blob and if you see the
example provided into MSDN and the Oracle documentation, they also use
blob.
Could you be more precise in your answer?

Thank you
Joël


Sahil Malik [MVP] a écrit :

[quoted text, click to view]

Kalpesh
9/22/2005 3:48:37 AM
Hi,

Can you specify the line at which the error/exception is raised ?

Kalpesh
Sahil Malik [MVP]
9/22/2005 10:13:51 AM
I'm guessing this one "ocm.ExecuteNonQuery();"


--

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
----------------------------------------------------------------------------
---------------

[quoted text, click to view]

Kalpesh
9/22/2005 11:30:00 AM
Hi Jonaze,

Add cmd.parameters.refresh before actually appending the parameters
This will get the names, types of all parameters to the store
procedures & the parameters collction will get pre-filled.

This way, you will be able to identify the parameters to the stored
proc, their parameter name, type, direction, size etc

This will help you know what is the parameter type for FILE_BINARY
parameter

Does this help

Kalpesh

PS - Do not use cmd.parameters.refresh in your actual code
AddThis Social Bookmark Button