Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Actually i am facing one problem while saving the text in sql database.
Example:-
One "A" person send a message to "B" person like below text entered in the textbox
"Hai
This is Ram"

But the above text is saving in DataBase like "Hai this is Ram" while displaying to "B" person it is showing like "Hai This is Ram". but what i want is
"Hai
This is Ram" in data base also it should save like this

Is it possible
Posted
Comments
Garth J Lancaster 17-Oct-14 1:30am    
so, what you're saying is, somewhere along the line (no pun), the formatting, perhaps a carriage return is missing ? I would have thought it depends more on how you read the lines from the textbox - if you're looping through the textbox, getting all the non-blank lines, then you should be appending them with '\r\n' inbetween them, shouldn't you ? .. I cant think of any issues actually storing a string with embedded '\r\n', but, when you write the recovered string to "B"'s textbox, you may need to do a 'split' on '\r\n' and write each line in turn
Garth J Lancaster 17-Oct-14 1:32am    
in fact, if you want to store the contents of the textbox as one field/string, you may as well use something else (hopefully that the user wont type), eg '|' as the separator, and split on that basis when the string is read back from the database
Maciej Los 17-Oct-14 2:19am    
Not enough information.
Please, provide more details about the field properties, table structure, used methods to save and read data.

I used below code while saving to database.here i am using multiline textbox thanks to every one who replied fastly for my question

txtMsgBody.InnerText.Replace("\r\n", "<br/>");
 
Share this answer
 
v2
Hi,

Did you try storing it in html format string into db ?
Also, I was thinking, what about trying, like this,

C#
"<pre>" + TextValue + "</pre>";


Thought code project does it, though with a better and a good code obviously :) :)

Regards,
Praneet
 
Share this answer
 
Comments
Rajesh waran 17-Oct-14 2:21am    
it may be leads to sql injection as refer from, http://www.w3schools.com/sql/sql_injection.asp

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