我们可以在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.