locked
how to retrieve html code save in sql? RRS feed

  • Question

  • User-1136231507 posted

    Hi, 

    I create Rich text Box by using Tiny_MCE I saved info inside sql by linq and now I want to retrieve saved info in That Rich Text Box

    how to do that?

    Plz help me Thanks.

    Sunday, September 14, 2014 9:34 AM

Answers

  • User281315223 posted

    Assuming you used the steps mentioned in this previous post to save the HTML contents of your TextBox into a SQL database, you can essentially do the opposite to pull the content that you need and display it :

    // Build your connection
    using(SqlConnection yourConnection = new SqlConnection("Your Database Connection String"))
    {
          // Build your query (to retrieve your HTML data)
          var query = "SELECT TOP 1 YourHTMLColumn FROM YourTable";
    
          // Open your connection
          yourConnection.Open();
    
          // Build a command to execute
          using(var yourCommand = new SqlCommand(query, yourConnection))
          {
                 // Execute your query
                 string html = Convert.ToString(yourCommand.ExecuteScalar());  
    
                 // Store your HTML contents in your RichTextBox
                 YourRichTextBox.Text = html;
          }
    }

    This is obviously just a very simplified example, but the basic logic is there.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 14, 2014 9:51 AM