Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to keep the text from a textarea in the same format inside SQL Database?

Posted on 2005-04-14
6
Medium Priority
?
1,787 Views
Last Modified: 2012-06-21
Ok,.. this question kinda spans over a couple areas, but since its mainly dealing with SQL, I put it here.

I have an ASP page with a form on it.  On the form is a large textarea for comments.  

On Submit, the textarea, along with the rest of the form fields goes to a ASP handler, which loads it all into a SQL table.

After that, I pull this information down onto another page.  When I pull it down, all the text from the textarea is run together without any formatting.

Is there anyway to send the text from the textara to the SQL Database and back down to the other page, while still retaining its spacing, tabs, and other formatting features?

0
Comment
Question by:DrinkGreen
  • 2
  • 2
  • 2
6 Comments
 
LVL 7

Expert Comment

by:LandyJ
ID: 13786551
You need to translate characters like carriage return (Chr(13)), double spaces, etc into their HTML equivalents.

Double spaces dispaly only as single space (html compacts it), so Replace(text, "  ", "  ")
CR  -- Replace(textarea, Chr(13), "<br")

this should get you started.

hth,
Landy
0
 
LVL 7

Expert Comment

by:LandyJ
ID: 13786575
Here's a routine I use:

DBField = HTMLEscape(texarea)

  Private Function HTMLEscape(ByVal xField As String) As String
    'Replace these characters with their HTML encoding: &, ', "
    xField = Replace(xField, "&", "&amp;")
    xField = Replace(xField, "'", "&#39;")
    xField = Replace(xField, """", "&quot;")

    'Get these Extended characters
    xField = Replace(xField, Chr(145), "&#39;") 'left single quotation mark to regular single quote
    xField = Replace(xField, Chr(146), "&#39;") 'right single quotation mark to regulare single quote
    xField = Replace(xField, Chr(147), "&quot;") 'left double quotation mark to regular double quote
    xField = Replace(xField, Chr(148), "&quot;") 'right double quotation mark to regular double quote
    xField = Replace(xField, Chr(150), "&ndash;") 'dash the length of 'n' character
    xField = Replace(xField, Chr(151), "&mdash;") 'dash the length of 'm' character
    xField = Replace(xField, Chr(188), "&frac14;") ' 1/4
    xField = Replace(xField, Chr(189), "&frac12;") '1/2
    xField = Replace(xField, Chr(190), "&frac34;") '3/4

    'Return Escaped field
    Return xField
  End Function
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 300 total points
ID: 13787114
Normal display of text on an HTML page exhibits the symptoms you describe.  That is the way web pages are supposed to work.

One possible option is to wrap the data in
      <PRE> ...your data here... </PRE>
tags.  That will make the text be displayed in a fixed-width font and it will preserve line-ends and so-forth... in breifl, it will probably look more like the original text.

-- Dan
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:DrinkGreen
ID: 13790901
So do I put the <PRE> </PRE> tags around the textarea, or inside it.... or do I put it on the page that pulls the text out of the database?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 13792418
Use it on the page that displays the output.

Odds are, the data in the database is formatted as desired, but it will depend upon what it includes.  If the Textarea contains <table> tages and other major formatting, then the issue will be more complex.  To verify/diagnose that, use Query Analyzer or other tool to examine the data in situ in the database.
0
 

Author Comment

by:DrinkGreen
ID: 13792451
No, I don't have any <table> tags in it.

That worked great!  Thanks for the tips DR.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question