Tuesday, November 24, 2009

C# SQL Encode/Decode

public string SqlEncode(string inStr)
{
inStr = inStr.Replace("'", "''");
inStr = inStr.Replace("<", "<");
inStr = inStr.Replace(">", ">");
return inStr;
}
public string SqlDecode(string inStr)
{
if (inStr == "")
return null;

inStr = inStr.Replace("''", "'");
inStr = inStr.Replace("<", "<");
inStr = inStr.Replace(">", ">");

return inStr;
}

No comments: