Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-20-2007, 12:03 PM   PM User | #1
nicky77
New Coder

 
Join Date: Aug 2007
Posts: 93
Thanks: 9
Thanked 0 Times in 0 Posts
nicky77 is an unknown quantity at this point
Displaying data retrieved from SQL Server

Hi there, I'm having trouble with £ signs and apostrophes when I'm retrieving data from my SQL Server database then displaying it on a web page. Is there a simple way round this type of problem, i.e using the Replace function? I've struggled to find an answer on the web so far and am now to using ASP and SQL Server. My columns are stored as varchar on the database.

thanks in advance for any help
nicky77 is offline   Reply With Quote
Old 11-20-2007, 12:50 PM   PM User | #2
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
It's a bit difficult to suggest a solution without seeing what code you're using to put data in or get data out of the database, or what display issues you're actually having.
Spudhead is offline   Reply With Quote
Old 11-20-2007, 01:22 PM   PM User | #3
nicky77
New Coder

 
Join Date: Aug 2007
Posts: 93
Thanks: 9
Thanked 0 Times in 0 Posts
nicky77 is an unknown quantity at this point
apologies - here are the relevant asp lines for retrieving a salary from the database
Code:
'Get job data
rs.Open "select * from vacancy where status = 'active' order by id desc", dbConn, 1 
Response.Write("<h4>Salary: " & rs("salary") & "</h4>")
and this is the code for inserting into the database, where salaryInput is a variable storing the value submitted in a form field
Code:
sqltext =  "insert into vacancy (title,....,creator) values ("
sqltext = sqltext & "'" & replace(salaryInput, "'", "''") & "', "
'the rest of the inserts
sqltext = sqltext & "'" & replace(Session("creator_id"), "'", "''") & "') "
dbConn.Execute(sqltext)
the problem with displaying the £ sign is in Safari, which displays a � instead.

the problem with the apostrophe is when i am retrieving data from the database to use as the title tag for an image - if there is an apostrophe in the image description, then the title tag cuts off the rest of the text after the apostrophe

i thought that both of these problems may be a result of the same issue, in terms of how i'm handling the data? hope this make more sense
nicky77 is offline   Reply With Quote
Old 11-21-2007, 12:36 PM   PM User | #4
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
Hmm. Yeah, you should be able to simply replace those characters.

Instead of this:
Code:
Response.Write("<h4>Salary: " & rs("salary") & "</h4>")
try this:
Code:
sSalary = rs.Fields("salary")
if sSalary <> "" then sSalary = replace(sSalary,"£","&pound;")
Response.Write("<h4>Salary: " & sSalary & "</h4>")
and replace an apostrophe with &rsquo;
Spudhead is offline   Reply With Quote
Users who have thanked Spudhead for this post:
nicky77 (11-21-2007)
Old 11-21-2007, 02:47 PM   PM User | #5
nicky77
New Coder

 
Join Date: Aug 2007
Posts: 93
Thanks: 9
Thanked 0 Times in 0 Posts
nicky77 is an unknown quantity at this point
thanks spudhead - problem solved!
nicky77 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:00 AM.


Advertisement
Log in to turn off these ads.