Ideally I would like to put all the code to access and fetch the data from the database in a separate utility files and all those methods at data binding times from the .net code behind file. The problem comes is when should the connection object be closed. For simple stuff, the helper method can close the connection but for things like DataGrid or GridView you can't close connection until you have bound the data to the GridView...so how can I do that in the best design way..so if I have class call DatabaseHelper and it has a method like public static DataSet fetchEmployeesData.... this method cant close the connection
- My other question is how do use the transactions and do atomic operations..so for example, if i have 3 or 4 methods in my db helper class say InsertX, InsertY, UpdateZ etc and i have to call all these operations in a transaction, how do i write such a code with a good design.. (in this example, I would be calling these methods from the aspx code behind file on some event say form submit)