Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    93
    Thanks
    9
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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.

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    93
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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;

  • Users who have thanked Spudhead for this post:

    nicky77 (11-21-2007)

  • #5
    New Coder
    Join Date
    Aug 2007
    Posts
    93
    Thanks
    9
    Thanked 0 Times in 0 Posts
    thanks spudhead - problem solved!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •