【发布时间】:2010-11-10 14:48:15
【问题描述】:
我正在数据库中存储和编辑包含一个或多个句子的长字符串的某些字段。每当我在文本框中输入单引号并想要保存它时,它都会引发异常,例如 “'l' 附近的语法不正确。 字符串 '' 后面的非闭合引号。" 有什么办法可以避免吗?
编辑: 查询是:
SqlCommand com = new SqlCommand("UPDATE Questions SET Question = '[" +
tbQuestion.Text + "]', Answer = '[" +
tbAnswer.Text + "]', LastEdit = '" +
CurrentUser.Login +
"'WHERE ID = '" + CurrentQuestion.ID + "'");
【问题讨论】:
-
请显示您正在使用的 SQL 语句。
-
简单地逃离 ' 与另一个 ' 像 Hell's Angels 到 Hell's Angels
-
SqlCommand com = new SqlCommand("UPDATE Questions SET Question = '[" + tbQuestion.Text + "]', Answer = '[" + tbAnswer.Text + "]', LastEdit = '" + CurrentUser.Login + "'WHERE ID = '" + CurrentQuestion.ID + "'");
-
我们都是这么想的。请编辑您的问题以添加该信息。
-
别担心。我会为你做的。
标签: sql dynamic-sql