Store RichTextBoxs content in Access

Hi Please help me in these problem. I really do appreciate that.

I am having a richtextbox with the text and image in the contain. The content of the richtextbox is pasted from a word file. Now i have to store that in a Access database.

I have tried with Oleobject but i can not get the oleobject from the richtextbox? There is no
richtextbox.oleobject like some of the article(That make me confuse too :-( )

Can you please tell me how to do it?If there is some line of example code that will be a great help.
Once again thanks in advance.

Best regards
[596 byte] By [duongthaiha] at [2007-11-20 9:04:31]
# 1 Re: Store RichTextBoxs content in Access
http://allenbrowne.com/Access2007.html
richTextBox == Memo fields, text boxes

but with access being a bit of an odd duck it could be that it only applys to a few versions and will likely not work in some...
Rudegar at 2007-11-9 11:33:53 >
# 2 Re: Store RichTextBoxs content in Access
http://allenbrowne.com/Access2007.html
richTextBox == Memo fields, text boxes

but with access being a bit of an odd duck it could be that it only applys to a few versions and will likely not work in some...
Thanks a lot for your help. But i am confused a bit

The Memo fields only accept character. Is that possible to store image as well?

Best regards
duongthaiha at 2007-11-9 11:34:54 >
# 3 Re: Store RichTextBoxs content in Access
I think RTF supports images so you can get the RTF from the rich text box (which is 8-bit text) and store it in the memo field.

RichTextBox has a property RTF which delivers the RTF for you to store in the database.

Darwen.
darwen at 2007-11-9 11:35:53 >
# 4 Re: Store RichTextBoxs content in Access
I think RTF supports images so you can get the RTF from the rich text box (which is 8-bit text) and store it in the memo field.

RichTextBox has a property RTF which delivers the RTF for you to store in the database.

Darwen.

Hi Thanks for your reply
I have tried to store the rtf in the Access where the field type is Memo. It throw an exception that is the query is too complex. it happen when there is an image in the richtextbox content. Can you please tell me what should i do?

Once again thanks a lot
duongthaiha at 2007-11-9 11:36:48 >
# 5 Re: Store RichTextBoxs content in Access
maybe you should look into Ole-Object
Rudegar at 2007-11-9 11:37:58 >
# 6 Re: Store RichTextBoxs content in Access
Are you trying to put the RTF string in the query string ?

e.g.

string query = string.Format("INSERT INTO MYTABLE (RTF) VALUES ('{0}')", _richTextBox.RTF);

This is very probably your problem.

You need to use parameterised queries e.g.

// assumes rich text box of _richTextBox
using (OdbcCommand command = new OdbcCommand("INSERT INTO MYTABLE (RTF) VALUES (@RTF)", _connection)
{
command.Parameters.AddWithValue("@RTF", _richTextBox.RTF);
command.ExecuteNonQuery();
}

As a side note you should be using parameterised queries all the time : they ensure that nomatter which database engine you're using the data is always formatted correctly for the database.

Darwen.
darwen at 2007-11-9 11:38:58 >
# 7 Re: Store RichTextBoxs content in Access
@Rudegar:Thank you very much. I have tried but is how can i get the oleobject from the richtextbox. There is a property name OleObject from the old version. But from C# 2005 it seem gone to me??

@darwen Thanks a lot for you reply
I have tried with code that you give me. The problem is when there is an image the Memo field is not long enough.

Anyone could you please tell me what should i do next. I really do appreciate that.
duongthaiha at 2007-11-9 11:39:52 >