Please help me with this because I cannot seem to get it right
I am trying to query a name(Daniel O’Neal) in column names tblStudents in an access database however access reports a syntax error with the statement:
Select * from tblStudents where name like 'Daniel O'Neal'
because of the apostrophe in the name.
How do I overcome this.
Thank you in advance
Advertisement
Answer
You escape '
by doubling it, so:
Select * from tblStudents where name like 'Daniel O''Neal'
Note that if you’re accepting “Daniel O’Neal” from user input, the broken quotation is a serious security issue. You should always sanitize the string or use parametrized queries.