This is your everyday typical SqlHelper helper class that's used on most projects that don't use Enterprise Library. We made one modification - it's not a static class, and it implements IDisposable, which means that you can use it in a using block, and have your connection cleaned up for you automatically:
using (SqlHelper helper = new SqlHelper())
  helper.Execute("update Orders set ShippedDate = GetDate() where OrderId = 1", CommandType.Text, null);

This helps us ensure that our data connections are cleaned up for us, because in the Dispose method, we check for an open connection, and if it's open, the helper closes it.

You can also use the overloaded constructor to pass in a custom connection string. This way you can build custom objects that are populated from multiple databases.

Last edited Jan 2, 2008 at 3:41 PM by banderson, version 5


No comments yet.