locked
Retaining text format in SQL Server table columns RRS feed

  • Question

  • Hi,

    I am capturing input in the UI using Rich Text Box. Users do formatting while entering the input. The problem is, when I read the data and store it in the database from rich text box to SQL Server 2005, I lose all the formatting done. Is there a way to maintain these format changes to the text while storing the data in SQL Server tables.

    Thanks & Regards,
    Subalakshmi Vijayarajan.

    Tuesday, June 8, 2010 10:08 AM

Answers

  • Hello,

    When you lose the RTF format, then something is wrong with your steps "reading from RTF box and writing to database".

    Are you using the property "Rtf" or "Text" of the rtf box? "Rtf" should be the right one.


    Olaf Helper ----------- * cogito ergo sum * errare humanum est * quote erat demonstrandum * Wenn ich denke, ist das ein Fehler und das beweise ich täglich http://olafhelper.over-blog.de
    Tuesday, June 8, 2010 10:37 AM
  • Hi,

    I got the solution. I have changed the RichTextBox content reading code in the following format.

    //select the range from which data needs to be retrieved

    TextRange textRange = new TextRange(paramRichTextBox.Document.ContentStart, paramRichTextBox.Document.ContentEnd);
    MemoryStream msData = new MemoryStream();
    textRange.Save(msData, DataFormats.Rtf);
    //get the data from the selected range
    //strData = textRange.Text;
    strData = msData.ToString();

    Thanks for your reply Olaf. I found this way out from your question only. Thanks for that.

    Do you have any idea of how to format a rich text content to a RDLC file?

    Thanks & Regards,
    Subalakshmi Vijayarajan.

    Tuesday, June 8, 2010 11:37 AM
  • For that search in the SQL Server Reporting forum for RTF, there are several posts. But yet I mostly saw "not supported".
    Olaf Helper ----------- * cogito ergo sum * errare humanum est * quote erat demonstrandum * Wenn ich denke, ist das ein Fehler und das beweise ich täglich http://olafhelper.over-blog.de
    Wednesday, June 9, 2010 4:34 AM

All replies

  • Hello,

    When you lose the RTF format, then something is wrong with your steps "reading from RTF box and writing to database".

    Are you using the property "Rtf" or "Text" of the rtf box? "Rtf" should be the right one.


    Olaf Helper ----------- * cogito ergo sum * errare humanum est * quote erat demonstrandum * Wenn ich denke, ist das ein Fehler und das beweise ich täglich http://olafhelper.over-blog.de
    Tuesday, June 8, 2010 10:37 AM
  • Hi Olaf,

    Thanks for your reply.

    The following is the code I use to read the text from the RichTextBox

    //select the range from which data needs to be retrieved

    TextRange textRange = new TextRange(paramRichTextBox.Document.ContentStart, paramRichTextBox.Document.ContentEnd);
    //get the data from the selected range
    strData = textRange.Text;

    Can you please help me how to read the text properly and insert it into the database table. Is there any property should be set to database table to retain the text format?

    Thanks & Regards,
    Subalakshmi Vijayarajan.

    Tuesday, June 8, 2010 10:58 AM
  • Which control do you use, it don't look like the the common RichTextBox, more like a HTML document?
    Olaf Helper ----------- * cogito ergo sum * errare humanum est * quote erat demonstrandum * Wenn ich denke, ist das ein Fehler und das beweise ich täglich http://olafhelper.over-blog.de
    Tuesday, June 8, 2010 11:21 AM
  • Hi,

    I got the solution. I have changed the RichTextBox content reading code in the following format.

    //select the range from which data needs to be retrieved

    TextRange textRange = new TextRange(paramRichTextBox.Document.ContentStart, paramRichTextBox.Document.ContentEnd);
    MemoryStream msData = new MemoryStream();
    textRange.Save(msData, DataFormats.Rtf);
    //get the data from the selected range
    //strData = textRange.Text;
    strData = msData.ToString();

    Thanks for your reply Olaf. I found this way out from your question only. Thanks for that.

    Do you have any idea of how to format a rich text content to a RDLC file?

    Thanks & Regards,
    Subalakshmi Vijayarajan.

    Tuesday, June 8, 2010 11:37 AM
  • For that search in the SQL Server Reporting forum for RTF, there are several posts. But yet I mostly saw "not supported".
    Olaf Helper ----------- * cogito ergo sum * errare humanum est * quote erat demonstrandum * Wenn ich denke, ist das ein Fehler und das beweise ich täglich http://olafhelper.over-blog.de
    Wednesday, June 9, 2010 4:34 AM