Implementing a Generic Data Access Layer in ADO.NET Part 3

Using the DBManager class
You can make use of the DBManager class as shown in the code snippet below.
DBManager dbManager = new DBManager();
dbManager.OpenConnection();
dbManager.ExecuteReader(“Select * from employee”);
while (dbManager.DBReader.Read())
Response.Write(dbManager.DBReader[“EmpName”].ToString());
dbManager.CloseConnection();
Note that the OpenConnection and the CloseConnection methods of the DBManager class invoke the Open and the Close methods of the DBManagerBase class internally.
Similarly, you can use the DBManager class to insert data as shown in the code snippet below.
DBManager dbManager = new DBManager();
String sql = “insert into employee (EmpCode, EmpName) values (‘E001”Joydip’)”;
try
{
dbManager.OpenConnection();
dbManager.ExecuteNonQuery(sql,CommandType.Text);
}
catch(Exception e)
{
HttpContext.Current.Response.Write(e);
}
finally
{
dbManager.CloseConnection();
HttpContext.Current.Response.Write(“<BR>”+”1 record added…”);
}
Conclusion
We have had a look at the strategies involved in the design and implementation of a Generic DAL framework in this series of articles on the Data Access Layer. Let me know your views/comments by sending me mails at joydipkanjilal@yahoo.com. I blog at http://aspadvice.com/blogs/joydip.]]>

Leave a comment

Your email address will not be published.