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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accomodating apostrophe in update statement

Status
Not open for further replies.

jjones100

Technical User
Nov 12, 2004
23
US
Notes are read in from the form:
Notes = request.form("notes")
I am using the following asp code to update my table:
strSQL = "UPDATE Tasks SET " _
& "Notes='" & Notes & "'," _
& "where RecNo like '" & RecNo & "'".
I get missing operator when someone enters text containing apostrophes in the Notes field, example: 345 test's.
How can i correctly code this so that the apostrophe does not cause a problem. Thanks for any help
 
Try this:
Code:
strSQL = "UPDATE tasks "
strSQL = strSQL & "SET notes = '" & Notes & "' "
strSQL = strSQL & "WHERE recno LIKE '" & RecNo & "' "

Take Care,
Mike
 
Doubling the apostrophe will solve the problem. Only one apostrophe will be entered in to the database. Try it.

Code:
strSQL = "UPDATE tasks "
strSQL = strSQL & "SET notes = '" & [!]Replace([/!]Notes[!], "'", ''")[/!] & "' "
strSQL = strSQL & "WHERE recno LIKE '" & RecNo & "' "

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Still getting same error: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression ''345 test's',DueDate=''where RecNo like '127''.
It seems the error comes from the word test's. The customer has type "345 test's" in the notes section and program is interpreting the apostrophe between the t and s as the end of the quote, causing the error. I submitted same note without the ' between t and s and program works fine. Any help appreciated.
 
Got it! Thanks George
Posted previous message before I saw your response.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top