SQL查询访问中带有撇号的文本 [英] SQL to Query text in access with an apostrophe in it

查看:116
本文介绍了SQL查询访问中带有撇号的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我,因为我似乎无法正确完成

Please help me with this because I cannot seem to get it right

我正在尝试在访问数据库中的列名称tblStudents中查询名称(Daniel O'Neal),但是访问报告了以下语句的语法错误:

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'

因为名字中的撇号.

我该如何克服这个问题.

How do I overcome this.

提前谢谢

推荐答案

通过将其加倍,可以逃避 ' ,所以:

You escape ' by doubling it, so:

Select * from tblStudents where name like 'Daniel O''Neal' 

请注意,如果您接受用户输入的"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.

这篇关于SQL查询访问中带有撇号的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆