0

hi i have an field has OracleClob type.I want to cast this as my string data.How can i do it in c# ?

 [MapField("MSG_BODY")]
 public Oracle.DataAccess.Types.OracleClob MsgBody { get; set; }

i want to set MsgBody : "This is a sample";

I have to define an oracleclob object and fill it as string text.

2 Answers 2

2

According to the Oracle documentation you need to write it with a buffered array, so something like this:

char[] writeBuffer = "This is a sample".ToCharArray();
this.MsgBody.Write(writerBuffer, 0, writeBuffer.Length);
this.MsgBody.Close();
this.MsgBody.Dispose();

and bear in mind I'm assuming you've created the OracleClob with an open OracleConnection.

Sign up to request clarification or add additional context in comments.

3 Comments

i use bltoolkit for oracle connection with connectionstr.I have no oracleconnection obj do i have to create it only for using this?
@Mennan: according to the documentation (if you look at the code example) you have to create an OracleClob with a connection. If this is being done by the framework you're leveraging, fine, I'm just letting you know that an OracleClob isn't a plain old class - it's special and requires some interesting initialization and interaction.
i understand the problem thx for your helping i research documentation.
2

I've never touched Oracle, but according to the documentation you can handle it like a byte stream.

Add a StreamWriter and you should be able to do

var sw = new StreamWriter(MsgBody, Encoding.UTF8); // Assuming you want UTF-8
sw.Write("This is a sample");
sw.Flush();

2 Comments

Where did you get the error from? Writing? Flushing? Saving? You may also need to always create a new OracleClob to write to, then assign it to the MsgBody.
error on writing.I use bltoolkit for connect to oracle.i think i have to create new connection only for creating new clob obj

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.