Hi there,
I hope I post this in the right section!!
I want to save an article in a sql server database. When the article is retrieved from the database, I want the formatting to be exactly the same as when it was saved ie. line breaks must be there and bold text must be shown, bulletpoints, etc.
Currently I save the full article in a single column defined as varchar(max). When I read the data in the column and display it on the webpage, all the line breaks that was in the article is not there anymore and the artcle is one long conitneous piece of text.
If I can use this post as an example. How would this post be stored in a sql database and when viewed, the formatting is still kept - line breaks intact and other formatting where it should be?
Hope I defined it properly and that someone would be able to help!!
Many thanks
Have a look at what you are sending to the database (in profiler), what is saved and what is returned.
I suspect you may need a varbinary rather than text.
It could also be being formatted by your app.
|||I have looked at Profiler. I am not really fimiliar with profiler, have not worked in it before.
What I can see though is that the data sent to the stored procedure does contain all the line breaks as required. I don't know how to check if the line breaks are still there when reading the data as profiler only shows the query that I used to retrieve the data or the SP name. Any help on how to check what the data looks like after its returned?
At the moment there is no formatting applied to the text as I use a textbox to enter it. All I want to achieve at the moment is to enter text and then return the text from the database with the line breaks that was entered using the textbox...
|||The varchar(max) should preserve your data from the text box.
Have you stopped your program prior to the insert to confirm that what is being inserted into SQL Server is in the proper format?
And if so, then query that data using SSMS to confirm that what is in the database is the same as what was entered.
That should help isolate where the formatting changes are occcuring.
|||The formatting is not being stripped, it probably does not exist the way you are pulling it.Look at how you got the data. Most downloads do NOT include formatting because they have no idea how you are going to present it.
|||
I think the problem might be this...
The line breaks are there in the database (as you entered them from your textbox) but you are rendering the text from the database on a web browser that pays no attention to your linebreaks.
Try something like this on your data returned from your database.
dbDataString.Replace(Environment.NewLine,"<br />")
No comments:
Post a Comment