我的字符串XML包含了一系列特殊字符:
&
egrave;
&
rsquo;
&
rsquo;
&
rsquo;
&
ldquo;
&
rdquo;
&
rsquo
&
agrave;
&
agrave;
我需要替换数据库插入字符串中的特殊字符,并且尝试使用System.Net.WebUtility.HtmlEncode失败,您能帮我吗?
string sql = "insert into rss (title, description, link, pubdate) values (?,?,?, " +
" STR_TO_DATE(?, '%a, %d %b %Y %H:%i:%s GMT'));";
OdbcCommand command;
OdbcDataAdapter adpter = new OdbcDataAdapter();
connection.Open();
command = new OdbcCommand(sql, connection);
command.Parameters.AddWithValue("param1", System.Net.WebUtility.HtmlEncode(xmlTitle.InnerText.ToString()));
command.Parameters.AddWithValue("param2", System.Net.WebUtility.HtmlEncode(xmlDescription.InnerText.ToString()));
command.Parameters.AddWithValue("param3", System.Net.WebUtility.HtmlEncode(xmlLink.InnerText.ToString()));
command.Parameters.AddWithValue("param4", System.Net.WebUtility.HtmlEncode(xmlPubDate.InnerText.ToString()));
adpter.InsertCommand = command;
adpter.InsertCommand.ExecuteNonQuery();
connection.Close();
您可以使用HttpUtility.HtmlDecode或在.NET 4.0及更高版本中也可以使用WebUtility.HtmlDecode
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句