I'm trying to insert a CLOB into Oracle 11g. I am using the following C# code:
parameter = cmd.Parameters.Add("SOURCETEXT", UniDbType.Clob);
parameter.Value = sSourceText;
cmd.Parameters.Add(parameter);
The parameter value is correct when I look at the debugger, however, I always get an error when I try to execute the query with:
cmd.ExecuteNonQuery();
I get the error "Can not convert." The UniDbType field in the cmd.Parameters for this has the following error in it.
UniDbType '((CoreLab.UniDirect.UniParameter)((new System.Collections.ArrayList.ArrayListDebugView(((CoreLab.Common.DbParameterBaseCollection)(cmd.Parameters.System.Collections.ICollection.SyncRoot)).InnerList)).Items[9])).UniDbType' threw an exception of type 'System.ArgumentException' CoreLab.UniDirect.UniDbType {System.ArgumentException}
Can someone tell me what I am doing wrong. I have fix or six other fields with the same structure (just different UniDbTypes) and they work fine.
Thanks.
Error inserting CLOB.
-
- Posts: 729
- Joined: Thu 13 Dec 2007 10:24
-
- Posts: 729
- Joined: Thu 13 Dec 2007 10:24
We reproduced the error. This bug will be fixed in the nearest future.
Meanwhile, as a temporary solution, you can use the UniBlob class for CLOB inserting.
See the example:
Meanwhile, as a temporary solution, you can use the UniBlob class for CLOB inserting.
See the example:
Code: Select all
using (UniConnection uniConnection = new UniConnection(myConnectionString)) {
uniConnection.Open();
UniCommand command = uniConnection.CreateCommand();
command.CommandText = "INSERT INTO uni_clob (ID, SOURCETEXT) VALUES (:ID, :SOURCETEXT)";
UniBlob uniBlob = CreateClob(uniConnection, "my string");
UniParameter param = new UniParameter("ID", UniDbType.Int);
param.Value = 1; // just test value, usually obtained from sequence
command.Parameters.Add(param);
param = new UniParameter("SOURCETEXT", UniDbType.Clob);
param.Value = uniBlob;
command.Parameters.Add(param);
command.ExecuteNonQuery();
}
private UniBlob CreateClob(string value) {
UniBlob uniBlob = new UniBlob(uniConnection, UniDbType.Clob);
byte[] chars = Encoding.Default.GetBytes(value);
uniBlob.Write(chars, 0, chars.Length);
return uniBlob;
}
---------------------------------------
Used table
CREATE TABLE UNI_CLOB (
ID NUMBER,
SOURCETEXT CLOB)