Reputation: 159
I want to insert string to oracle database as clob data type in c#. How can I do this? some codes for example:
private static byte[] GetByteArr(string listParameter)
{
if (listParameter!=null)
{
return Encoding.Unicode.GetBytes(listParameter);
}
else
{
return Encoding.Unicode.GetBytes(string.Empty);
}
}
byte[] toArr = GetByteArr((string)eMessageList[1]);
emailParameters[1] = command.Parameters.Add("pEto",OracleDbType.Clob, toArr,ParameterDirection.Input);
command.ExecuteNonQuery();
this code insert toArr
to database as System.Byte[]
.
Upvotes: 0
Views: 8607
Reputation: 84
Although the question seems to be outdated, I want to share an example that worked for me.
My intention was to save a JSON string (with more than 32k characters) into a clob field.
This is what I did:
string JSON_string = JsonConvert.SerializeObject(SomeObject);
System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand();
myCommand.Parameters.AddWithValue("", SomeAttribute);
myCommand.Parameters.AddWithValue("", SomeAttribute2);
myCommand.Parameters.AddWithValue("", SomeAttribute3);
myCommand.Parameters.AddWithValue("", JSON_string);
And then execute the command. I'm using our companies library to do that:
DataSet myDS = myUser.myLoginUser._MySpAppS.RunSQL("INSERT INTO MARS$T_BCSAVINGS (MASSNAHMEN_ID, USER_ID, AKTIV, HEBELDATEI) VALUES (?, ?, ?, ?);", myCommand.Parameters);
I'm saving the result in a DataSet only to check if the query was successful.
So basically what I did, is to handover the string to the OleDbCommand parameters list and executed the query with those parameters.
Upvotes: 0
Reputation: 126
try this
byte[] newvalue = System.Text.Encoding.Unicode.GetBytes(mystring);
var clob = new OracleClob(db);
clob.Write(newvalue, 0, newvalue.Length);
Upvotes: 3