Skip to content

Instantly share code, notes, and snippets.

@talkingdotnet
Created February 27, 2018 05:45
Show Gist options
  • Save talkingdotnet/891cce45735cbf78b39dbcd59cf3ee31 to your computer and use it in GitHub Desktop.
Save talkingdotnet/891cce45735cbf78b39dbcd59cf3ee31 to your computer and use it in GitHub Desktop.
private object ConvertDataTypes(object col)
{
if (col == null)
return "NULL";
switch (col.GetType().FullName)
{
case "System.Int16":
case "System.Int32":
case "System.Int64":
case "System.UInt16":
case "System.UInt32":
case "System.UInt64":
case "System.Byte":
case "System.SByte":
case "System.Single":
case "System.Double":
case "System.Decimal":
case "System.Boolean":
return col;
case "System.DBNull":
return "NULL";
case "System.Guid":
case "System.String":
return $"\"{col.ToString().Replace("\"", "\\\"").Replace("'", "\\'")}\"";
case "System.DateTime":
return $"\"{((DateTime)col).ToString("yyyy-MM-dd HH:mm:ss")}\"";
case "System.Byte[]":
return "0x" + BitConverter.ToString((byte[])col).Replace("-", "");
}
return col;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment