3 tier app, data access layer, business logic layer

May 9 2010 2:17 AM
hi friends,
I want to develop 3 tier app but I still confused how to implement it

1. In data access layer, could I return datareader? it's the better approach? some people tell it is not good way, you better used arrayList.

2. I have one method with 3 transaction inside (insert, update, delete)
I make this in business layer, so that the OleDBConnection (open and close), OleDbTransaction placed in business layer and I pass this as parameter to data access layer, is that good way?

3. if anyone have the good tutorial especially in C#, please tell me.

this is my sample code, please tell me + -

DAL
 
  1. public static OleDbDataReader GetAll(OleDbConnection conn, bool status)
  2. {
  3. try
  4. {
  5. string query =
  6. "SELECT [Id], [Name], [CreatedDate], [CreatedBy], " +
  7. " [UpdatedDate], [UpdatedBy] " +
  8. "FROM [Role] " +
  9. "WHERE [Status] = @pStatus " +
  10. "ORDER BY [Name] ASC";
  11.  
  12. OleDbCommand cmd = new OleDbCommand(query, conn);
  13. OleDbParameter pStatus = cmd.Parameters.Add("@pStatus",
  14. OleDbType.Boolean);
  15. pStatus.Value = status;
  16. OleDbDataReader dr = cmd.ExecuteReader();
  17.  
  18. return dr;
  19. }
  20. catch (OleDbException ex)
  21. {
  22. throw new Exception("OleDb Error: " + ex.Message);
  23. }
  24. catch (Exception ex)
  25. {
  26. throw ex;
  27. }
  28. }

BLL
 
  1. public List<Role> GetAll(bool status)
  2. {
  3. List<Role> listRole = new List<Role>();
  4.  
  5. try
  6. {
  7. if (conn.State != ConnectionState.Open)
  8. {
  9. conn.Open();
  10. }
  11.  
  12. OleDbDataReader dr = RoleData.GetAll(conn, status);
  13.  
  14. if (dr.HasRows)
  15. {
  16. while (dr.Read())
  17. {
  18. Role role = new Role();
  19. role.Id = int.Parse(dr["Id"].ToString());
  20. role.Name = dr["Name"].ToString();
  21. role.CreatedBy = dr["CreatedBy"].ToString();
  22. role.CreatedDate = (string.Empty.Equals(dr["CreatedDate"].ToString()) ?
  23. DateTime.MinValue :
  24. DateTime.Parse(dr["CreatedDate"].ToString()));
  25. role.UpdatedBy = dr["UpdatedBy"].ToString();
  26. role.UpdatedDate = (string.Empty.Equals(dr["UpdatedDate"].ToString()) ?
  27. DateTime.MinValue :
  28. DateTime.Parse(dr["UpdatedDate"].ToString()));
  29. listRole.Add(role);
  30. }
  31. }
  32.  
  33. return listRole;
  34. }
  35. catch (OleDbException ex)
  36. {
  37. throw new Exception("OleDb Error: " + "\n" + ex.Message);
  38. }
  39. catch (Exception e)
  40. {
  41. throw new Exception(e.Message);
  42. }
  43. finally
  44. {
  45. conn.Close();
  46. }
  47. }

Thanks

Answers (1)