Skip to content

Instantly share code, notes, and snippets.

@duncansmart
Created January 12, 2012 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duncansmart/1601540 to your computer and use it in GitHub Desktop.
Save duncansmart/1601540 to your computer and use it in GitHub Desktop.
Dump SqlCommand
static void DumpCommand(SqlCommand command)
{
foreach (SqlParameter p in command.Parameters)
{
Debug.Write("DECLARE " + p.ParameterName + " " + p.SqlDbType.ToString().ToLower());
if (p.Size > 0)
Debug.Write("(" + p.Size + ")");
Debug.Write(" = ");
if (p.Value is Enum)
Debug.Write((int)p.Value);
else if (p.Value is bool)
Debug.Write((bool)p.Value ? 1 : 0);
else if (p.Value is short || p.Value is int || p.Value is long || p.Value is decimal || p.Value is float || p.Value is double)
Debug.Write(p.Value);
else if (p.Value is DateTime)
Debug.Write("'" + ((DateTime)p.Value).ToString("yyyy-MM-ddTHH:mm:ssZ")+"'");
else
Debug.Write("'" + p.Value + "'");
Debug.WriteLine(";");
}
Debug.WriteLine(command.CommandText);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment