我的字符串
XML包含一系列特殊字符:
& egrave; & rsquo; & rsquo; & rsquo; & ldquo; & rdquo; & rsquo & agrave; & agrave;
我需要在DB中插入字符串中替换此特殊字符,我尝试使用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