如何将html保存到数据库字段

leo*_*ora 2 html sql-server asp.net-mvc

我有一个很小的编辑器网页,我的用户可以使用这个编辑器,我将html保存到我的数据库中.

我有问题将此HTML保存到我的数据库.例如,如果有一个带有"'"的名称,或者如果有其他html字符"<,",">"等,我的代码似乎会在插入时爆炸.

是否有关于获取任意html的最佳实践,并将其完全保留到db字段而不必担心任何特定字符.

Jef*_*ver 6

我想知道你是否正在构建完整的查询.而是使用参数化查询,这应该消除您的数据问题.

string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

SqlCommand cmdIns = new SqlCommand(sqlIns, db.Connection);
cmdIns.Parameters.Add("@name", info);
cmdIns.Parameters.Add("@information", info1);
cmdIns.Parameters.Add("@other", info2);
cmdIns.ExecuteNonQuery();
Run Code Online (Sandbox Code Playgroud)