[thelist] Apostrophes

Jonathan_A_McPherson at rl.gov Jonathan_A_McPherson at rl.gov
Fri May 31 15:47:00 CDT 2002


Rob,

Assuming that "var" is what you want to encode, just use the VBScript
"Replace" function:

Replace (var, "'", "''")

In SQL, you can escape a single apostrophe by putting another in front of
it.

'don''t' = don't

Jonathan.

-----Original Message-----
From: Rob Smith [mailto:rob.smith at thermon.com]
Sent: Friday, May 31, 2002 1:32 PM
To: Thelist (E-mail)
Subject: [thelist] Apostrophes


--
[ Picked text/plain from multipart/alternative ]


Hey this is interesting:

I've got a <textarea></textarea> and a snippet of ASP code for you to look
at.

----------------------------
| This isn't a message.    |
|                          |
|__________________________|

strSQL = "INSERT INTO CMSSocial (CMSSocialTitle, CMSSocialBody,
CMSSocialEdited, CMSSSubmit, CMSUserID, CMSEditorID)  VALUES  (' " &
strTitle & " ', ' " & strBody & " ', ' " & strEdited & " ', ' " & strSubmit
& " ', ' " & findit.Fields.item("CMSUserID").value & " ', ' " &
findit2.Fields.item("CMSUserID").value & " ')"

When I try to do the SQL command I get an error saying:
Line 1: Incorrect syntax near 't'.
Which means when the code tries to insert this message into the database, it
gets hung up on the apostrophe and pukes.

Any ideas how I can allow my users to include conjunctions? Do I need to
change up the order of my apostrophes?

(Jay said: you need to escape the apostrophe's. ) No offence Jay, Other
ideas?

Rob




More information about the thelist mailing list