Link to home
Start Free TrialLog in
Avatar of mj_stanton
mj_stantonFlag for Australia

asked on

How do I Databind a Rich Text Box Control with MS SQL Server ntext field so it does not loose its rich text changes?


Hi

I have a simple Winforms application built in VB.Net 2003 were I am using a Rich Text Box Control to bind to a field on a MS SQL Server 2000 (ntext field called "Content" .

I have built the Command buttons to bold specific text sections and so on but when I save the data and reload it again changes to the content are made but the formating changes are not saved.

The binding code I am using is as follows;

RichTextBox_Content.DataBindings.Add(New System.Windows.Forms.Binding("Text", SQL_QuickDocEDIT_DataSet, "MSSP_QuickDoc_EDIT_SelectCommand.Content"))

Should I be using something else instead of "Text"? or Should I be binding to a different SQL datatype? or doing something else?

Thanks in Advance

Kind Regards

Matthew
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mj_stanton

ASKER

I tried changing the "Text" property to "rtf" instread of "text" (as follows) but it was not sucessful ;

TextBox_Regarding_Subject.DataBindings.Add(New System.Windows.Forms.Binding("rtf", SQL_QuickDocEDIT_DataSet, "MSSP_QuickDoc_EDIT_SelectCommand.Regarding-Subject"))
Avatar of Sancler
Sancler

In what way was it not successful?  

I'm not an adept at MS SQL but, from what I do know, ntext should be the right sort of datatype.  It looks - from such documentation as I have - to be as virtually "open-ended" as an Access memo field.

Was nothing passed to the database?  Did what was passed to the database not display with formatting when it was returned?   If you look at the relevant field in the database/datatable through some sort of text reader (e.g. message box, or debug.writeline) did it have any rtf formatting code in it?

Given that rtf is just string data - all its formatting is done by embedded strings - there is no reason why it shouldn't save to any database.  But without knowing more about where the link between what was in the textbox and what later got back to the textbox was broken, it's very difficult to start guessing how to put it right.

Roger
Sorry Roger

I should have provided more information. Appartently from some follow up research I did MS made the Rtf property unavailable as standard in the property editor in Visual Studio 2003.

When I use the original binding statement the data loads I can edit the text and save the changes and it comes  back when I reload the data from the database but any RTF changes I make such as bold is lost when I send the SQLUpdatecommand .

Thanks

Matthew
When I use "Rtf" instead for "TEXT" in the Databinding I get a error Data Access Application block saying "Invalid file format".
I figured it out "Rtf" is correct, the problem was that I was not creating a new record each time. This means I was loading data created in plain text and from when I was using "Text" in the databinding statement.

When I created a new record using "RTF" property in the Databinding statement it worked fine.

Roger thanks your first reply did lead to the correct solution it was the implementation that was the problem.

Regards

Matthew
Matthew

Thanks for letting me know, and for the points.  I was just pondering how to guide you step by step through a debugging process.  But that won'te be necessary now ;-)

Roger