Created
September 7, 2012 17:11
-
-
Save jamesrcounts/3667853 to your computer and use it in GitHub Desktop.
A text formatter for SqlCommand instances
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
| /// <summary> | |
| /// Formats the command. | |
| /// </summary> | |
| /// <param name="command">The command.</param> | |
| /// <returns>A formatted <see cref="SqlCommand"/></returns> | |
| private static string FormatCommand(SqlCommand command) | |
| { | |
| string result = command.CommandText + Environment.NewLine; | |
| result = string.Format("{0}{{{1}", result, Environment.NewLine); | |
| foreach (var item in command.Parameters) | |
| { | |
| result = result + new string(' ', 4); | |
| var p = item as SqlParameter; | |
| result = p == null ? | |
| result + "NULL" : | |
| result + string.Join(", ", p.ParameterName, p.SqlDbType, p.Size, p.Value); | |
| result = result + Environment.NewLine; | |
| } | |
| result = string.Format("{0}}}{1}", result, Environment.NewLine); | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment