Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can Any One Tell Me That How To Save and Retrieve the Bold Text and para change in sqlserver
I have a text Box and user want to save a specific word BOLD when retrieve from database which was stored by himself
Posted
Updated 20-Mar-19 16:07pm
Comments
Shubham Choudhary 18-Mar-13 1:51am    
hi!! when you write any content in textbox so it is behave like normal string!! but if you want to save different type of text save in sqlserver so save as html text and when you retrieve text on your website it shows like which you want...

save data in RTF or HTML format

you can use Richtextbox control

Happy Coding!
:)
 
Share this answer
 
Comments
8400593361 18-Mar-13 8:24am    
when i am using rich textbox and save it into the database then an error is displaying

A potentially dangerous Request.Form value was detected from the client (FreeTextBox1="HELLO").
my code is:
con.ConnectionString = ConfigurationManager.ConnectionStrings["trialmlmConnectionString"].ConnectionString;


SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;

//demo1(@text nvarchar(max))
cmd.CommandText = "demo1";
cmd.Parameters.AddWithValue("@text", FreeTextBox1.Text);
try
{
con.Open();
cmd.ExecuteNonQuery();
con.Close();

}
catch (Exception ex)
{
Response.Write(ex.Message);
}
Aarti Meswania 18-Mar-13 8:32am    
datatype in sql should be varbinary(max) you can get sample code online
While saving to database you fetch value using
JavaScript
innerHTML 
property witch will give you text with html tags and after retrieving and loading in page you need to use
C#
Server.HtmlDecode(strValue)
methode to convert back to html format.
where strValue is the varchar value with html tag '<b>bold</b>'
 
Share this answer
 
v2
Just use the Editor and save that data in sql server and that field should be NVARCHAR
so what you save you will get back same when you retrieve.
 
Share this answer
 
You can convert the formatted text into Binary and save it into DB with VARBINARY datatype,

when retriving again you need to convert binary to the text format.
 
Share this answer
 
when i am using rich textbox and save it into the database then an error is displaying

A potentially dangerous Request.Form value was detected from the client (FreeTextBox1="dafzfs").

con.ConnectionString = ConfigurationManager.ConnectionStrings["trialmlmConnectionString"].ConnectionString;


        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.StoredProcedure;
      
        //demo1(@text nvarchar(max))
        cmd.CommandText = "demo1";
        cmd.Parameters.AddWithValue("@text", FreeTextBox1.Text);
        try
        {
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
           
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900