locked
Storing RTF data in SQL Server RRS feed

  • Question

  • Hi Manfred,
    I to have the same issue ...have you found any solution...the one thing i can give us solution for your problem is by getting the entered text as it is..(user Rtf.Text)..

    Thank you
    Monday, January 12, 2009 10:52 AM

Answers

  • Bharanidharan - That is one way that it can be done.

    A second option is to store the data as a blob. A very good sample can be found here: http://www.developer.com/net/net/article.php/3373951
    Saturday, January 17, 2009 6:43 PM
  • Mike has a very good linkas far as importing a file/image into sql.  The only thing I would add is, if using SQL 2205 or 2008 assure that you are using an appropriate data type.  the IMAGE, NTEXT, and TEXT data type will be deprecated in future releases of SQL:
    http://msdn.microsoft.com/en-us/library/ms187993.aspx

    For a .rtf or document I would recommend using a VARBINARY(MAX) data type and in SQL 2005 and 2008 you can insert a file directly with T-SQL using the OPENROWSET and BULK operator:

     
     
    CREATE TABLE #temp(  
    col1    VARBINARY(MAX)  
    );  
    GO  
     
    INSERT #temp 
    SELECT *  
    FROM OPENROWSET(BULK 'C:\resistance.doc',  
       SINGLE_BLOB) AS x;  
    GO  
     
    DROP TABLE #temp 

    Hope this helps
    David Dye
    Sunday, January 18, 2009 1:12 PM

All replies

  • Bharanidharan - That is one way that it can be done.

    A second option is to store the data as a blob. A very good sample can be found here: http://www.developer.com/net/net/article.php/3373951
    Saturday, January 17, 2009 6:43 PM
  • Mike has a very good linkas far as importing a file/image into sql.  The only thing I would add is, if using SQL 2205 or 2008 assure that you are using an appropriate data type.  the IMAGE, NTEXT, and TEXT data type will be deprecated in future releases of SQL:
    http://msdn.microsoft.com/en-us/library/ms187993.aspx

    For a .rtf or document I would recommend using a VARBINARY(MAX) data type and in SQL 2005 and 2008 you can insert a file directly with T-SQL using the OPENROWSET and BULK operator:

     
     
    CREATE TABLE #temp(  
    col1    VARBINARY(MAX)  
    );  
    GO  
     
    INSERT #temp 
    SELECT *  
    FROM OPENROWSET(BULK 'C:\resistance.doc',  
       SINGLE_BLOB) AS x;  
    GO  
     
    DROP TABLE #temp 

    Hope this helps
    David Dye
    Sunday, January 18, 2009 1:12 PM