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

Posted on 2006-07-14
Last Modified: 2008-01-09


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

Question by:mj_stanton
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 34

Accepted Solution

Sancler earned 500 total points
ID: 17109236

Author Comment

ID: 17109560
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"))
LVL 34

Expert Comment

ID: 17110144
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.

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.


Author Comment

ID: 17110443
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 .



Author Comment

ID: 17110539
When I use "Rtf" instead for "TEXT" in the Databinding I get a error Data Access Application block saying "Invalid file format".

Author Comment

ID: 17110742
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.


LVL 34

Expert Comment

ID: 17110847

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 ;-)


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.Net - String Manipulation Scenario 2 46
VB.NET System.NullReferenceException 1 44
SSIS - Using VB.NET to parse XML file 11 43 code 9 29
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question