You can create a public class with static functions to handle the opening and closing of you connections. Since the “….do something” will be different you can try something like:
public class DbConnection
private static SQLConnection mConnection = new SQLConnection(ConnectionSource);
public static void openConnection(bool aOpenAConnection)
if ( aOpenAConnection )
ConnectionSource is just that, the source for the connection, assuming that all of your forms will use the same connection. If not, you can pass the connection in.
Hmm. You could put all of the data access code in the class, using a switch statement to handle the different cases of “… do something”. Of course, you will need to adjust it a bit for connection sharing.
I hope these suggestions help.