Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preserve text formatting from SQL Table 1

Status
Not open for further replies.

jon24422531

Technical User
Jan 27, 2004
295
GB
Hi

We have a VBA Outlook application where users insert text in to a SQL table from a form. This text has formatting with carriage returns etc.

When I use ASP to select this data and display it on a web page the formatting is lost, especially the carriage returns and the text is just one long string. Is there any way to select from a SQL table and preserve the formatting?

Many thanks

Jonathan
 
The same thing would happen if you open a plain formatted text file in your browser because HTML ignores the returns, tabs, etc.

The way to get the browser to show the desired format is to insert some HTML into the text string.

You can use the HTML tag [tt]<br>[/tt] to force a new line....

So by using the Replace() function in ASP on the string from your database, you can insert the HTML format:
[tt]HTMLString = Replace(TextString, vbCrLf, vbCrLf & "<br>" & vbCrLf)[/tt]


The next most important thing is perhaps the "tab" so you'd modify the statement above to insert &nbsp;&nbsp;&nbsp; in place of vbTab.
 
Guys thanks for the replies:

Sheco, I tried your suggestion, but I am unsure how to apply it, I've tried several ways but it just errors and I don't know where to put the REPLACE() function. I will keep experimenting.

ChrisHirst, I'd like to try your suggestion but where do I put the <pre> tags?

As a further complication, the text I am selecting for display in an HTML table comprises two fields linked as one:

Code:
strSQL = "select FaultNo, (Fault) + (resolution) as Description, CONVERT(CHAR(20),CreateDate,0) from Worklog..worklog where  faultno = '" & sCode & "'"
Which I then display thus:
Code:
<table border='0'>
<tr>
<%
	for each fieldItem in rsData.fields
		Response.Write vbTab & vbTab &"<td bgcolor=""#EBDDE2""><strong>" & fieldItem.name
		Response.Write "</strong></td>" & vbCrLf
	next
		Response.Write vbTab & "</tr>" & vbCrLf
%>
</tr>
<%

Do While not rsData.EOF
	Response.Write "<tr>"
	for each fieldItem in rsData.fields
	Response.Write "<td>&nbsp;" & fieldItem.value & "</td>"
	next
	Response.Write "</tr>"
	rsData.MoveNext
Loop
%>
</table>
<%
The main problem is that this is a little 'extra' project outside of my normal work and I don't do enough of this coding malarkey to become any good......

Jonathan
 
In your code above, inside the <td> that holds the content.


and to use the replace function would be;

Code:
... & Replace(fieldItem.value, vbCrLf, vbCrLf & "<br>" & vbCrLf) & ...

Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top