Skip to content

Instantly share code, notes, and snippets.

@bungard
Last active September 16, 2015 00:45
Show Gist options
  • Save bungard/34ec40915f676171fbf2 to your computer and use it in GitHub Desktop.
Save bungard/34ec40915f676171fbf2 to your computer and use it in GitHub Desktop.
private static void SQLServerEscapeObject(object obj)
{
foreach (System.Reflection.PropertyInfo property in obj.GetType().GetProperties())
{
try
{
if (property.PropertyType.FullName == "System.String" && property.GetValue(obj, null) != null)
{
property.SetValue(obj, property.GetValue(obj, null).ToString().Replace("'", "''"), null);
}
}
catch (Exception e) { Logger.Log("Issue clensing SQL query: " + e.Message, Logger.Loglevel.Warning); }
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment