Created
November 11, 2012 04:37
-
-
Save lorddev/4053736 to your computer and use it in GitHub Desktop.
Tiny method that wraps the delegate you pass into it with standard connection/command using blocks
This file contains 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> | |
/// Speeds up DAL development by reducing repeated code. | |
/// </summary> | |
private void OpenConnectionAndDispose(string storedProcedure, Action<SqlCommand> action) | |
{ | |
using (var conn = new SqlConnection(connectionString)) | |
{ | |
using (var command = new SqlCommand(query, conn)) | |
{ | |
command.CommandType = CommandType.StoredProcedure; | |
action(command); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment