在表中插入单引号的问题 [英] Problem in inserting single quotes in Table

查看:84
本文介绍了在表中插入单引号的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我有一点怀疑。当用户在文本字段中输入'(单引号)时。

插入表格时,它会给我们错误。

但我在少数网站看到过 - Facebook,Code Project允许'(单引号)并显示相同的内容。

任何人都可以指导我。

Dear Friends,

I have small doubt. When user enters the ' (single quotes) in the text field.
While inserting in Table, it give us the error.
But I have seen in few sites eg- Facebook,Code Project where they allow ' (single quotes) and display the same.
Can anyone guide me on this.

推荐答案

Omit id列一起,它将自动填充。要使用你的变量,你应该参数化你的SQL查询。



参考:



insert-data-into-sql-server-from-c-sharp-code



单引号 - 转义 - 在字符串中插入到数据库中



Omit the id column altogether, it will be populated automatically. To use your variable, you should parameterise your SQL query.

Reference :

insert-data-into-sql-server-from-c-sharp-code

single-quotes-escape-during-string-insertion-into-a-database

cmd.Parameters.Add("@name", SqlDbType.VarChar);


你必须转义单引号,即将单引号转换为双引号引号'',然后您可以将单引号插入表中。请查看这篇文章:



http://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx [ ^ ]
You have to escape the single quote, that is turn a single quotes ' into double single quotes '', then you can insert as single quote into a table. Please check out this article:

http://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx[^]


这篇关于在表中插入单引号的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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