Created
January 12, 2012 16:45
-
-
Save duncansmart/1601540 to your computer and use it in GitHub Desktop.
Dump SqlCommand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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