Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Text Formatting

Author  Topic 

prpball
Starting Member

19 Posts

Posted - 2008-12-31 : 13:52:39
Can SQL Server 2005 retain formatted text?
If so, does anyone know how to send the formatted text to SQL?

I am using asp.net and want to insert text that is formatted in that textbox into sql and be able to bring it back as it was put in.

For example, line breaks, font bolding, size, etc.

revdnrdy
Posting Yak Master

220 Posts

Posted - 2008-12-31 : 14:34:44
ntext datatype in SQL Server will store Html markup

Try storing your html in an ntext field (column). Then retrieve it onto your webpage to see the results.

r&r
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-12-31 : 14:38:42
From Books On line
ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead. For more information, see Using Large-Value Data Types.

Jim
Go to Top of Page

prpball
Starting Member

19 Posts

Posted - 2008-12-31 : 14:48:18
Thanks, I am currently using nvarchar(200).
The users that will be inputting the text do not know html markup.
Is there another way of doing this?
Go to Top of Page

revdnrdy
Posting Yak Master

220 Posts

Posted - 2008-12-31 : 15:47:50
Well the users of your form won't be required to know html markup.

Once they type something into the textbox it is up to the code behind the textbox to handle the submission. A textbox is a asp.net form control isn't it? You as the coder would handle the data in the textbox once it is submitted across the web server and eventually to the sql server. You define what styling to use (ie.. font color, bold text etc..).

How is the formatting applied? Does the user have a handful of buttons they can press which inserts html for them (like on this forum?)
Go to Top of Page

prpball
Starting Member

19 Posts

Posted - 2008-12-31 : 15:55:17
No buttons.
When they hit the return button they get a new line.
How do I know when they have used a return button in code and when I submit that to sql it takes it as a one long string. I need to be able to pull that text back out of sql in the same format it was submitted in.

For example,
Name
Address
City, State Zip

I need the above to go into sql with the breaks and come back out with those same line breaks.

Does that help?
Go to Top of Page

revdnrdy
Posting Yak Master

220 Posts

Posted - 2008-12-31 : 16:37:25
Well here is the short answer..

A newline gets appended to the users data on every press of the return key inside your asp.net textbox form control.

To use your example..

Name,\n OR possibly Name,\r\n
City,\n OR possibly City, \r\n

You would need to detect this with your asp code before inserting into the database. You then need to replace those values with <br> so the string will become Name,<br>City,<br>.

This is presuming that you display the data in html and are not using asp.net calls to print the data.



Go to Top of Page

prpball
Starting Member

19 Posts

Posted - 2009-01-05 : 11:25:19
I would be reading the information from SQL by using a datasource and outputting the information into a datalist templated column. When I read the information from sql how would I now keep the formatting.
Go to Top of Page
   

- Advertisement -