save and retrieve rtf RRS feed

  • Question

  • Hi,
    i have a richtextbox control in my application, and want to know how to save and retrieve formatted text in a MS SQL DB.

    I found this example in the forum, but I don't know how to use it. Can you please help me solve the problem?  Where should I write the code below?


    I've just tried it and able to do this successfully.

    I basically did this:

  • load the RTF into the RTB control
  • created a SQL command, simple basic insert statement:


    SqlCommand theSQLCommand = new SqlCommand("INSERT INTO [TableName] (Field) VALUES (@p1)");
    SqlParameter theSQLParameter = new SqlParameter("@p1", SqlDbType.Text);
    theSQLParameter.Value = this.theRichTextBox.RTF;
    theSQLCommand.Connection = new SqlConnection(ConnectionString);



    then to retrieve it, I did this, again, specifically for this example


    this.theRichTextBox.Text = String.Empty;
    SqlCommand theSQLCommand = new SqlCommand("SELECT [Field] FROM [TableName] WHERE [ID] = 1");
    theSQLCommand.Connection = new SqlConnection(ConnectionString);
    SqlDataReader theReader = theSQLCommand.ExecuteReader(CommandBehavior.CloseConnection);
    while (theReader.Read())
       this.theRichTextBox.RTF = theReader.GetValue(0).ToString();



    And was able to do this fine and got all the formatting etc... correctly.

Wednesday, July 18, 2007 1:35 PM

All replies

  • What is your actual problem ? Do you get an error somewhere ?

    Jens K. Suessmeyer.


    Wednesday, July 18, 2007 7:03 PM
  • I want to save and retrieve the formatted content of a richtextbox in and from sql db.but when I format text and try to save it, this error message appear : " update requires proper update command when trying to updatr modified rows."


    Thursday, July 19, 2007 11:49 AM