sql有不少转义字符,需要注意一下,转换一下再存进去就Ok了
public string EnCode(string content)
{
string str1=content.Replace("<","<");
string str2=str1.Replace(">",">");
string str3=str2.Replace("'","'");
string str4=str3.Replace(" "," ");
string str5=str4.Replace("/r/n","<br>");
string str6=str5.Replace("/"",""");
string str7=str6.Replace("&","&");
return str7;
}
public string UnCode(string content)
{
string str1=content.Replace("&","&");
string str2=str1.Replace(""","/"");
string str3=str2.Replace("<br>","/r/n");
string str4=str3.Replace(" "," ");
string str5=str4.Replace("'","'");
string str6=str5.Replace(">",">");
string str7=str6.Replace("<","<");
return str7;
}
}

博客指出SQL存在不少转义字符,需进行转换后存储。给出了两个方法,EnCode方法将特定字符替换为转义字符,UnCode方法则将转义字符还原,以此实现对SQL转义字符的处理。
2455

被折叠的 条评论
为什么被折叠?



