在 Access 2003 SQL 中清理字符串:' 问题
我正在编写一个查询,该查询必须计算注册课程的学生人数,我的做法如下:
DCount("[student/course table].[Student ID]","[student/course table]","[StartDate] = #" & [Course Start Date] & "# AND Location = '" & tblCourseDetails.Location & "' AND [Course Number] = '" & [Course Number] & "'")
问题是 Location 可以包含撇号,这会给我的结果带来错误。这似乎搞砸了很多事情(比如它要求我输入参数两次)。有什么简单的方法可以绕过撇号吗?我想也许使用 Replace()=Replace() 这将是一个非常简单的解决方案,但如果还有其他方法可以解决这个问题,我想知道。
我不太担心 SQL 注入。无论如何,要使用此查询,您几乎可以访问数据库。
这不是我的全部问题,如果您认为我应该发布它,请告诉我。
I'm writing a query that has to count the number of students enrolled in a course, and the way I'm doing it is like this:
DCount("[student/course table].[Student ID]","[student/course table]","[StartDate] = #" & [Course Start Date] & "# AND Location = '" & tblCourseDetails.Location & "' AND [Course Number] = '" & [Course Number] & "'")
The problem is that Location can contain apostrophes, which throws errors into my results. This seems to screw up a lot of things (like it asks for me to enter a parameter twice). Is there any simple way to get around apostrophes? I was thinking maybe using Replace()=Replace() which would be a pretty simple solution, but if there's any other ways around this I'd like to know.
I'm not too worried about SQL injection. To use this query you'd have pretty much access to the database anyways.
This isn't my whole query, if you think I should post it, tell me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要添加转义字符。对于访问,我相信它是“”。
因此,找到 ' 并将其替换为 '' 就可以了。
编辑:这是一个额外的撇号,而不是双引号。
You need to add an escape character. For access I believe it is '' for '.
So find and replace ' with '' and you should be good to go.
Edit: That is an extra apostrophe, not a double quotation mark.