Skip to content

Instantly share code, notes, and snippets.

@lorddev
Created November 11, 2012 04:37
Show Gist options
  • Save lorddev/4053736 to your computer and use it in GitHub Desktop.
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
/// <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