我必须将 SQL 语句作为字符串插入数据库,例如:
string content = "insert into myTable(content) values ('" + myContent + "')";
string sql = "insert into myTable2(sqlStatement) values ('" + content + "')";
显然这不起作用,因为'
inside content
,所以我添加了以下内容:
Console.WriteLine(content);
content = content.Replace("'", "\\'");
Console.WriteLine(content);
我确定变量content
已更改,但仍有错误ExecuteNonQuery()
我也尝试了以下方法,都失败了:
content = content.Replace("'", "\\\'");
content = content.Replace("'", "\\\\'");
content = content.Replace("'", @"\'");