Saving rich text to an Access Database

Trying to write a SQL statement to add a record to a database. Is there anything special about Memo fields that would make them different than a text field Or is there anything special about how C# would send an RTF string

I have a rich text box and when a button is clicked, I put the rich text from that box into a string variable, then use a SQL statement to try to save the string to an access database.

This is a screen shot of the error I get.

http://img.photobucket.com/albums/v215/jdonner/error.jpg

My best guess is the \'s in the rich text are making the exception, but I tried using the @ in front of the variable and in front of the rich text and both still caused the error.



Answer this question

Saving rich text to an Access Database

  • Anders Lassen

    It is unlikely that the escape characters are causing you an issue as they are generally only used when displaying or entering a string, not when storing it in this way.

    From the looks of it though... you aren’t actually firing a SQL query, look at what is inside of the quotes in the exception.

    I do suggest that you make sure that you’ve got a legitimate query that you are firing off, also, look into using Parameters as part of your command so as to sanitize your string to reduce the likelihood of this kind of problem. You can find an article on using Parameters here: http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson06.aspx



  • JaredK

    Thanks Brendan, this is exactly what was wrong. I was used to passing simple values so something complex like rich text was throwing it off.

    I had never heard of parameters before, thank you very much for the link, I'll read through it tonight.


  • Saving rich text to an Access Database