Anton Lieskovsky
Anton Lieskovsky

Reputation: 189

C#, Oracle - How to store TEXT as BLOB

I am coding in C# and I have following problem with Oracle DB. I would like to store some TEXT in BLOB column but I do not know how. Do you have any idea how to change my code?

String textValue = "Some example of text..."

oraCommand.CommandText = "UPDATE BLOB_TABLE SET BLOB_COLUMN = :data WHERE ID='123'";
                oraCommand.Parameters.Add(":data", OracleDbType.Blob);
                oraCommand.Parameters[":data"].Value = textValue;
                oraCommand.ExecuteNonQuery();
            }

Upvotes: 1

Views: 2469

Answers (1)

hkutluay
hkutluay

Reputation: 6944

You must remove ":" while binding parameters. And BLOB is binary object, you should convert string to byte array. You should use CLOB for character large objects.

String textValue = "Some example of text..."

oraCommand.CommandText = "UPDATE BLOB_TABLE SET BLOB_COLUMN = :data WHERE ID='123'";
OracleParameter param  =  oraCommand.Parameters.Add("data", OracleDbType.Blob);
param.Value = Encoding.ASCII.GetBytes(textValue);
oraCommand.ExecuteNonQuery();

Upvotes: 3

Related Questions