Solved

Replace carriage return with < BR > in a MS SQL Database using ASP

Posted on 2007-04-03
14
801 Views
Last Modified: 2008-01-09
I am running an ASP page to enter data into an MS SQL database into a text field (NVARCHAR) when the user enters a carriage return in the database it records it as two little squares. what I need to do is make a replace(FieldName, "TheSquare", "<Br>") so it will render the return as HTML however I can't seem to find what the "TheSquare" needs to be in order to replace it.  

I have tried REPLACE(FieldName, vbCrLf, "< br> ")
I have tried  REPLACE(REPLACE(FieldName, CHR(10), " < br > "), CHR(13), " < br > ")

*Note: I had to add spaces in the code example above becuse Experst Exchange Javescript failed when I tried to post the question

with no luck
0
Comment
Question by:Jason Jones
  • 5
  • 4
  • 3
  • +2
14 Comments
 
LVL 18

Expert Comment

by:mgfranz
ID: 18843061
Try this;

(Replace(FieldName, vbCr, "<br>"))
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18843066
Hmm - what about simply:
  Replace(FieldName, chr(13), "<br>")

Is that still leaving the square symbol?
0
 
LVL 8

Expert Comment

by:i2mental
ID: 18843079
Try REPLACE(Fieldname, char(13)+char(10), '<br>')
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 1

Author Comment

by:Jason Jones
ID: 18843173
Ok I tried all three and none work...  REPLACE(Fieldname, char(13)+char(10), '<br>') actually crashed the whole application.  the other two did nothing

Thanks
0
 
LVL 11

Expert Comment

by:flipz
ID: 18843204
Try
replace(fieldname, vbcrlf,"</br>")
0
 
LVL 11

Expert Comment

by:flipz
ID: 18843210
Sorry - didn't see you already tried it - works for varchar columns though.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18843212
What about we try to find out what's there?
You sure it's a carriage return?
Try this in your code:

response.write Instr(FieldName, chr(13))
response.write Instr(FieldName, chr(10))

Do either return any numbers?
0
 
LVL 1

Author Comment

by:Jason Jones
ID: 18843246
Both return 0
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18843261
So there's no carriage return or line break in there...
Hmm...sure that the user is hitting /enter/ ?

What about

response.write Instr(FieldName, vbTab)
0
 
LVL 1

Author Comment

by:Jason Jones
ID: 18843361
It also says 0  

I know there is a return in there because I am the one entering it. The application is still under development.  If I look at the actual Data using SQL enterprise manager I can see the little squares (there are actually 2 of them side by side for any carriage returns I enter)   Here is an exmaple of soneone else with a similar problem with Excel but the same thing is happening to me with SQL
http://www.gossamer-threads.com/forum/General_C8/Databases_and_SQL_F36/Delete_Carriage_return_query_P259718/
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 250 total points
ID: 18843392
Hmm - then what about we try to split the data by that character?

newData=Split(FieldName, chr(13))

Response.Write lbound(newData)
Response.Write ubound(newData)

Do either of those return anything?
0
 
LVL 11

Assisted Solution

by:flipz
flipz earned 250 total points
ID: 18843748
Can you post example output directly from the database without any replacement? Is there any characters that get displayed?
0
 
LVL 1

Author Comment

by:Jason Jones
ID: 18843789
I actually just found the problem...  REPLACE(TheField, vbCrLf, "<br>")  DOES work.  Apparently I had declared two variables using that field and the first one was the one I kept changing and testing however what I was seeing on the website was actually second variable which did not have the replace function.  I'll split the points since you both have been helpful
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18843800
Glad you got it sorted! :^)
0

Featured Post

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MSSQL join different row from other table 14 65
Help needed in sql query 4 26
Hide and Unhide Table 6 24
SQL Syntax 6 27
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

685 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