我们可以在SQL中用单引号插入String吗? [英] can we insert String with single quotations in sql?
本文介绍了我们可以在SQL中用单引号插入String吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想在SqlCE中插入一个带有单引号的字符串,例如"StringName".
有人有主意吗?请和我分享.
谢谢,
Balu.
Hi all,
I want to insert a string with single quotations like this ''StringName'' in SqlCE.
any one have idea? please share with me.
Thanks,
Balu.
推荐答案
是的.听起来您可能将字符串连接到SQL语句.不要那样做而是使用 SqlParameter [
Yes it is. Sounds like you may concatenate strings to you SQL statement. Don''t do that. Instead use SqlParameter[^]. With parameters you won''t have any problems with quotation marks
据我所知,您想在字符串文字中使用单引号,因此请使用双引号将其与SQL命令区分开单引号,例如:
As I understood your question you want to have single quote in your string literals so use it double to distinguish it from the SQL command single quote , for example :
insert into names(name) values ('John')
将插入John
,但:
will insert John
, but :
insert into names(name) values ('''John''')
将插入''John''
.
或:
will insert ''John''
.
or :
insert into names(name) values ('o''reilly')
将插入 o''reilly
希望对您有所帮助.
will insert o''reilly
Hope it helps.
这篇关于我们可以在SQL中用单引号插入String吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文