ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to deal with the character ' in a SQL string (https://www.excelbanter.com/excel-programming/356434-how-deal-character-sql-string.html)

KS Wong[_2_]

How to deal with the character ' in a SQL string
 
Dear all,

Please give me some hints to tackle the following problem: -

strSQL = "Select location from restaurant where name = '" & strName & "'"
rstResult.open strsql, adoconnection, adOpenKeyset, adLockOptimistic

** if the string variable strName contains the character ['], i.e.
Benjimin's Restaurant, then error occurs.

Thanks in advance!

Keith


Tim Williams

How to deal with the character ' in a SQL string
 
Try doubling up the quotes before running the SQL

Benjimin''s Restaurant

(that's two single quotes, not a double quote)

Tim

"KS Wong" wrote in message
...
Dear all,

Please give me some hints to tackle the following problem: -

strSQL = "Select location from restaurant where name = '" & strName & "'"
rstResult.open strsql, adoconnection, adOpenKeyset, adLockOptimistic

** if the string variable strName contains the character ['], i.e.
Benjimin's Restaurant, then error occurs.

Thanks in advance!

Keith





All times are GMT +1. The time now is 02:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com