Codificar datos para insertar en campos de SQL.
public string encodeHTML(string str)
{
string regExp = "\\";
str = str.Replace(regExp, "\");
regExp = "\"";
str = str.Replace(regExp, """);
regExp = " '";
str = str.Replace(regExp, "'");
regExp = "<";
str = str.Replace(regExp, "<");
regExp = ">";
str = str.Replace(regExp, ">");
regExp = " ";
str = str.Replace(regExp, " ");
regExp = "¡";
str = str.Replace(regExp, "¡");
regExp = "¢";
str = str.Replace(regExp, "¢");
regExp = "£";
str = str.Replace(regExp, "£");
regExp = "¤";
str = str.Replace(regExp, "¤");
regExp = "¥";
str = str.Replace(regExp, "¥");
regExp = "¦";
str = str.Replace(regExp, "¦");
regExp = "§";
str = str.Replace(regExp, "§");
regExp = "¨";
str = str.Replace(regExp, "¨");
regExp = "©";
str = str.Replace(regExp, "©");
regExp = " ª ";
str = str.Replace(regExp, "ª");
regExp = "«";
str = str.Replace(regExp, "«");
regExp = "¬";
str = str.Replace(regExp, "¬");
regExp = "®";
str = str.Replace(regExp, "®");
regExp = "¯";
str = str.Replace(regExp, "¯");
regExp = "°";
str = str.Replace(regExp, "°");
regExp = "±";
str = str.Replace(regExp, "±");
regExp = "²";
str = str.Replace(regExp, "²");
regExp = "³";
str = str.Replace(regExp, "³");
regExp = "´";
str = str.Replace(regExp, "´");
regExp = " µ ";
str = str.Replace(regExp, "µ");
regExp = "¶";
str = str.Replace(regExp, "¶");
regExp = "·";
str = str.Replace(regExp, "·");
regExp = "¸";
str = str.Replace(regExp, "¸");
regExp = "¹";
str = str.Replace(regExp, "¹");
regExp = " º ";
str = str.Replace(regExp, "º");
regExp = "»";
str = str.Replace(regExp, "»");
regExp = "¼";
str = str.Replace(regExp, "¼");
regExp = "½";
str = str.Replace(regExp, "½");
regExp = "¾";
str = str.Replace(regExp, "¾");
regExp = "¿";
str = str.Replace(regExp, "¿");
regExp = "×";
str = str.Replace(regExp, "×");
regExp = "÷";
str = str.Replace(regExp, "÷");
regExp = " À ";
str = str.Replace(regExp, "À");
regExp = " Á ";
str = str.Replace(regExp, "Á");
regExp = " Â ";
str = str.Replace(regExp, "Â");
regExp = " Ã ";
str = str.Replace(regExp, "Ã");
regExp = " Ä ";
str = str.Replace(regExp, "Ä");
regExp = " Å ";
str = str.Replace(regExp, "Å");
regExp = " Æ ";
str = str.Replace(regExp, "Æ");
regExp = " Ç ";
str = str.Replace(regExp, "Ç");
regExp = " È ";
str = str.Replace(regExp, "È");
regExp = " É ";
str = str.Replace(regExp, "É");
regExp = " Ê ";
str = str.Replace(regExp, "Ê");
regExp = " Ë ";
str = str.Replace(regExp, "Ë");
regExp = " Ì ";
str = str.Replace(regExp, "Ì");
regExp = " Í ";
str = str.Replace(regExp, "Í");
regExp = " Î ";
str = str.Replace(regExp, "Î");
regExp = " Ï ";
str = str.Replace(regExp, "Ï");
regExp = " Ð ";
str = str.Replace(regExp, "Ð");
regExp = " Ñ ";
str = str.Replace(regExp, "Ñ");
regExp = " Ò ";
str = str.Replace(regExp, "Ò");
regExp = " Ó ";
str = str.Replace(regExp, "Ó");
regExp = " Ô ";
str = str.Replace(regExp, "Ô");
regExp = " Õ ";
str = str.Replace(regExp, "Õ");
regExp = " Ö ";
str = str.Replace(regExp, "Ö");
regExp = " Ø ";
str = str.Replace(regExp, "Ø");
regExp = " Ù ";
str = str.Replace(regExp, "Ù");
regExp = " Ú ";
str = str.Replace(regExp, "Ú");
regExp = " Û ";
str = str.Replace(regExp, "Û");
regExp = " Ü ";
str = str.Replace(regExp, "Ü");
regExp = " Ý ";
str = str.Replace(regExp, "Ý");
regExp = " Þ ";
str = str.Replace(regExp, "Þ");
regExp = " ß ";
str = str.Replace(regExp, "ß");
regExp = " à ";
str = str.Replace(regExp, "à");
regExp = " á ";
str = str.Replace(regExp, "á");
regExp = " â ";
str = str.Replace(regExp, "â");
regExp = " ã ";
str = str.Replace(regExp, "ã");
regExp = " ä ";
str = str.Replace(regExp, "ä");
regExp = " å ";
str = str.Replace(regExp, "å");
regExp = " æ ";
str = str.Replace(regExp, "æ");
regExp = " ç ";
str = str.Replace(regExp, "ç");
regExp = " è ";
str = str.Replace(regExp, "è");
regExp = " é ";
str = str.Replace(regExp, "é");
regExp = " ê ";
str = str.Replace(regExp, "ê");
regExp = " ë ";
str = str.Replace(regExp, "ë");
regExp = " ì ";
str = str.Replace(regExp, "ì");
regExp = " í ";
str = str.Replace(regExp, "í");
regExp = " î ";
str = str.Replace(regExp, "î");
regExp = " ï ";
str = str.Replace(regExp, "ï");
regExp = " ð ";
str = str.Replace(regExp, "ð");
regExp = " ñ ";
str = str.Replace(regExp, "ñ");
regExp = "ò";
str = str.Replace(regExp, "ò");
regExp = "ó";
str = str.Replace(regExp, "ó");
regExp = "ô";
str = str.Replace(regExp, "ô");
regExp = "õ";
str = str.Replace(regExp, "õ");
regExp = "ö";
str = str.Replace(regExp, "ö");
regExp = "ø";
str = str.Replace(regExp, "ø");
regExp = "ù";
str = str.Replace(regExp, "ù");
regExp = "ú";
str = str.Replace(regExp, "ú");
regExp = "û";
str = str.Replace(regExp, "û");
regExp = "ü";
str = str.Replace(regExp, "ü");
regExp = "ý";
str = str.Replace(regExp, "ý");
regExp = "þ";
str = str.Replace(regExp, "þ");
regExp = "ÿ";
str = str.Replace(regExp, "ÿ");
regExp = "∀";
str = str.Replace(regExp, "∀");
regExp = "∂";
str = str.Replace(regExp, "∂");
regExp = "∃";
str = str.Replace(regExp, "∃");
regExp = "∅";
str = str.Replace(regExp, "∅");
regExp = "∇";
str = str.Replace(regExp, "∇");
regExp = "∈";
str = str.Replace(regExp, "∈");
regExp = "∉";
str = str.Replace(regExp, "∉");
regExp = "∋";
str = str.Replace(regExp, "∋");
regExp = "∏";
str = str.Replace(regExp, "∏");
regExp = "∑";
str = str.Replace(regExp, "∑");
regExp = "−";
str = str.Replace(regExp, "−");
regExp = "∗";
str = str.Replace(regExp, "∗");
regExp = "√";
str = str.Replace(regExp, "√");
regExp = "∝";
str = str.Replace(regExp, "∝");
regExp = "∞";
str = str.Replace(regExp, "∞");
regExp = "∠";
str = str.Replace(regExp, "∠");
regExp = "∧";
str = str.Replace(regExp, "∧");
regExp = "∨";
str = str.Replace(regExp, "∨");
regExp = "∩";
str = str.Replace(regExp, "∩");
regExp = "∪";
str = str.Replace(regExp, "∪");
regExp = "∫";
str = str.Replace(regExp, "∫");
regExp = "∴";
str = str.Replace(regExp, "∴");
regExp = "∼";
str = str.Replace(regExp, "∼");
regExp = "≅";
str = str.Replace(regExp, "≅");
regExp = "≈";
str = str.Replace(regExp, "≈");
regExp = "≠";
str = str.Replace(regExp, "≠");
regExp = "≡";
str = str.Replace(regExp, "≡");
regExp = "≤";
str = str.Replace(regExp, "≤");
regExp = "≥";
str = str.Replace(regExp, "≥");
regExp = "⊂";
str = str.Replace(regExp, "⊂");
regExp = "⊃";
str = str.Replace(regExp, "⊃");
regExp = "⊄";
str = str.Replace(regExp, "⊄");
regExp = "⊆";
str = str.Replace(regExp, "⊆");
regExp = "⊇";
str = str.Replace(regExp, "⊇");
regExp = "⊕";
str = str.Replace(regExp, "⊕");
regExp = "⊗";
str = str.Replace(regExp, "⊗");
regExp = "⊥";
str = str.Replace(regExp, "⊥");
regExp = "⋅";
str = str.Replace(regExp, "⋅");
regExp = "Α";
str = str.Replace(regExp, "Α");
regExp = "Β";
str = str.Replace(regExp, "Β");
regExp = "Γ";
str = str.Replace(regExp, "Γ");
regExp = "Δ";
str = str.Replace(regExp, "Δ");
regExp = "Ε";
str = str.Replace(regExp, "Ε");
regExp = "Ζ";
str = str.Replace(regExp, "Ζ");
regExp = "Η";
str = str.Replace(regExp, "Η");
regExp = "Θ";
str = str.Replace(regExp, "Θ");
regExp = "Ι";
str = str.Replace(regExp, "Ι");
regExp = "Κ";
str = str.Replace(regExp, "Κ");
regExp = "Λ";
str = str.Replace(regExp, "Λ");
regExp = "Μ";
str = str.Replace(regExp, "Μ");
regExp = "Ν";
str = str.Replace(regExp, "Ν");
regExp = "Ξ";
str = str.Replace(regExp, "Ξ");
regExp = "Ο";
str = str.Replace(regExp, "Ο");
regExp = "Π";
str = str.Replace(regExp, "Π");
regExp = "Ρ";
str = str.Replace(regExp, "Ρ");
regExp = "Σ";
str = str.Replace(regExp, "Σ");
regExp = "Τ";
str = str.Replace(regExp, "Τ");
regExp = "Υ";
str = str.Replace(regExp, "Υ");
regExp = "Φ";
str = str.Replace(regExp, "Φ");
regExp = "Χ";
str = str.Replace(regExp, "Χ");
regExp = "Ψ";
str = str.Replace(regExp, "Ψ");
regExp = "Ω";
str = str.Replace(regExp, "Ω");
regExp = "α";
str = str.Replace(regExp, "α");
regExp = "β";
str = str.Replace(regExp, "β");
regExp = "γ";
str = str.Replace(regExp, "γ");
regExp = "δ";
str = str.Replace(regExp, "δ");
regExp = "ε";
str = str.Replace(regExp, "ε");
regExp = "ζ";
str = str.Replace(regExp, "ζ");
regExp = "η";
str = str.Replace(regExp, "η");
regExp = "θ";
str = str.Replace(regExp, "θ");
regExp = "ι";
str = str.Replace(regExp, "ι");
regExp = "κ";
str = str.Replace(regExp, "κ");
regExp = "λ";
str = str.Replace(regExp, "λ");
regExp = "μ";
str = str.Replace(regExp, "μ");
regExp = "ν";
str = str.Replace(regExp, "ν");
regExp = "ξ";
str = str.Replace(regExp, "ξ");
regExp = "ο";
str = str.Replace(regExp, "ο");
regExp = "π";
str = str.Replace(regExp, "π");
regExp = "ρ";
str = str.Replace(regExp, "ρ");
regExp = "ς";
str = str.Replace(regExp, "ς");
regExp = "σ";
str = str.Replace(regExp, "σ");
regExp = "τ";
str = str.Replace(regExp, "τ");
regExp = "υ";
str = str.Replace(regExp, "υ");
regExp = "φ";
str = str.Replace(regExp, "φ");
regExp = "χ";
str = str.Replace(regExp, "χ");
regExp = "ψ";
str = str.Replace(regExp, "ψ");
regExp = "ω";
str = str.Replace(regExp, "ω");
regExp = "ϑ";
str = str.Replace(regExp, "ϑ");
regExp = "ϒ";
str = str.Replace(regExp, "ϒ");
regExp = "ϖ";
str = str.Replace(regExp, "ϖ");
regExp = "Œ";
str = str.Replace(regExp, "Œ");
regExp = "œ";
str = str.Replace(regExp, "œ");
regExp = "Š";
str = str.Replace(regExp, "Š");
regExp = "š";
str = str.Replace(regExp, "š");
regExp = "Ÿ";
str = str.Replace(regExp, "Ÿ");
regExp = "ƒ";
str = str.Replace(regExp, "ƒ");
regExp = "ˆ";
str = str.Replace(regExp, "ˆ");
regExp = "˜";
str = str.Replace(regExp, "˜");
regExp = " ";
str = str.Replace(regExp, " ");
regExp = " ";
str = str.Replace(regExp, " ");
regExp = " ";
str = str.Replace(regExp, " ");
regExp = " ";
str = str.Replace(regExp, "‎");
regExp = "–";
str = str.Replace(regExp, "–");
regExp = "—";
str = str.Replace(regExp, "—");
regExp = "‘";
str = str.Replace(regExp, "‘");
regExp = "’";
str = str.Replace(regExp, "’");
regExp = "‚";
str = str.Replace(regExp, "‚");
regExp = "“";
str = str.Replace(regExp, "“");
regExp = "”";
str = str.Replace(regExp, "”");
regExp = "„";
str = str.Replace(regExp, "„");
regExp = "†";
str = str.Replace(regExp, "†");
regExp = "‡";
str = str.Replace(regExp, "‡");
regExp = "•";
str = str.Replace(regExp, "•");
regExp = "…";
str = str.Replace(regExp, "…");
regExp = "‰";
str = str.Replace(regExp, "‰");
regExp = "′";
str = str.Replace(regExp, "′");
regExp = "″";
str = str.Replace(regExp, "″");
regExp = "‹";
str = str.Replace(regExp, "‹");
regExp = "›";
str = str.Replace(regExp, "›");
regExp = "‾";
str = str.Replace(regExp, "‾");
regExp = "€";
str = str.Replace(regExp, "€");
regExp = "™";
str = str.Replace(regExp, "™");
regExp = "←";
str = str.Replace(regExp, "←");
regExp = "↑";
str = str.Replace(regExp, "↑");
regExp = "→";
str = str.Replace(regExp, "→");
regExp = "↓";
str = str.Replace(regExp, "↓");
regExp = "↔";
str = str.Replace(regExp, "↔");
regExp = "↵";
str = str.Replace(regExp, "↵");
regExp = "⌈";
str = str.Replace(regExp, "⌈");
regExp = "⌉";
str = str.Replace(regExp, "⌉");
regExp = "⌊";
str = str.Replace(regExp, "⌊");
regExp = "⌋";
str = str.Replace(regExp, "⌋");
regExp = "◊";
str = str.Replace(regExp, "◊");
regExp = "♠";
str = str.Replace(regExp, "♠");
regExp = "♣";
str = str.Replace(regExp, "♣");
regExp = "♥";
str = str.Replace(regExp, "♥");
regExp = "♦";
str = str.Replace(regExp, "♦");
return str;
}
Con esta funcion se puede guardar un query dentro de un campo o codigos especiales en una base de datos sin que generen conflictos en un INSERT o UPDATE
Codificar datos con EncodeHTML Query
Full Stack Software Developer.
Fundador de Kitaokatech y creador del ERP Hanbai.