How to deal with apostrophes?

Results 1 to 2 of 2

Thread: How to deal with apostrophes?

  1. #1
    Join Date
    Dec 1969
    Posts
    294

    Default How to deal with apostrophes?

    Hello,<BR><BR>I am retrieving info from a form and feed a Ms Access db with it.<BR>The problem is that some fields (titre and descrip) are likely to contain " &#039 " (apostrophe) signs. And of course this messes up the SQL query.<BR>How can I deal with that?<BR><BR>&#060;%<BR><BR>Set db = Server.CreateObject("ADODB.Connection")<BR>db.Open "newsites"<BR><BR>strSQL = "INSERT INTO websites (titre_site, adresse_site, cat, description, listepays) VALUES (" &_ <BR><BR><BR>"&#039" & request.form("titre") + "&#039, " &_ <BR>"&#039" & request.form("url") + "&#039, " &_ <BR>"&#039" & request.form("categ") + "&#039, " &_ <BR>"&#039" & request.form("descrip") + "&#039, " &_ <BR>"&#039" & request.form("pays") + "&#039)" <BR><BR>db.Execute strSQL<BR><BR>&#037;&#062;

  2. #2
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: How to deal with apostrophes?

    What you want to do is replace all instances of "&#039" with "&#039&#039". If SQL sees "&#039&#039" it knows that you mean just one. :)<BR><BR>So, before you construct your SQL string, do this:<BR><BR>Dim titre, URL, categ, descrip, pays<BR>titre = Replace(request.form("titre"), "&#039", "&#039&#039")<BR>URL = Repalce(request.form("URL"),"&#039","&#039&#039")< BR>...<BR><BR>strSQL = "INSERT INTO websites (titre_site, adresse_site, cat, description, listepays) VALUES (" &_ <BR>"&#039" & titre + "&#039, " &_ <BR>"&#039" & URL + "&#039, " &_ <BR>...<BR><BR>Does that make sense? Good luck, and happy programming!

Posting Permissions

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