Ticket T667339
Visible to All Users

Save RichTextEdit to MSSQL Database

created 7 years ago (modified 7 years ago)

Hello.  I am searching for a sample VB.NET code on how to save a RichTextEdit control to an MSSQL database nvarbinary(MAX) field.  I'm trying to use the control's .RtfText but I get a "…string cannot be converted to 1 dimentional array of byte" error.

I would appreciate getting a sample line of code for the saving part.

Answers approved by DevExpress Support

created 7 years ago (modified 7 years ago)

Hello Yoshihisa,
The RtfText property returns a string in the Rtf format. Since the nvarbinary(MAX) field accepts only binary data, the exception occurs. Use the RichEditControl.OpenXmlBytes property (instead of RtfText) to obtainthe control's content as an array of bytes in Office Open XML (Docx) format and pass this array to your database.
Should you need further assistance, feel free to contact me.

    Comments (2)
    YA YA
    Yoshihisa Akune 7 years ago

      Hi Mariya,

      I am now able to save and load to and from MSSQL with the following code:

      Save to MSSQL:
      .RefDocument = rtfRefDoc.OpenXmlBytes

      Load from MSSQL:
      rtfRefDoc.OpenXmlBytes = .RefDocument.ToArray

      I have a separate data access class to handle my database operation.

      Thank you.

      Maria Nikulina (DevExpress) 7 years ago

        You are welcome. Please do not hesitate to contact us in the future.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.