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
public static OleDbDataReader GetAll(OleDbConnection conn, bool status) { try { string query = "SELECT [Id], [Name], [CreatedDate], [CreatedBy], " + " [UpdatedDate], [UpdatedBy] " + "FROM [Role] " + "WHERE [Status] = @pStatus " + "ORDER BY [Name] ASC"; OleDbCommand cmd = new OleDbCommand(query, conn); OleDbParameter pStatus = cmd.Parameters.Add("@pStatus", OleDbType.Boolean); pStatus.Value = status; OleDbDataReader dr = cmd.ExecuteReader(); return dr; } catch (OleDbException ex) { throw new Exception("OleDb Error: " + ex.Message); } catch (Exception ex) { throw ex; } }
|
BLL
public List<Role> GetAll(bool status) { List<Role> listRole = new List<Role>(); try { if (conn.State != ConnectionState.Open) { conn.Open(); } OleDbDataReader dr = RoleData.GetAll(conn, status); if (dr.HasRows) { while (dr.Read()) { Role role = new Role(); role.Id = int.Parse(dr["Id"].ToString()); role.Name = dr["Name"].ToString(); role.CreatedBy = dr["CreatedBy"].ToString(); role.CreatedDate = (string.Empty.Equals(dr["CreatedDate"].ToString()) ? DateTime.MinValue : DateTime.Parse(dr["CreatedDate"].ToString())); role.UpdatedBy = dr["UpdatedBy"].ToString(); role.UpdatedDate = (string.Empty.Equals(dr["UpdatedDate"].ToString()) ? DateTime.MinValue : DateTime.Parse(dr["UpdatedDate"].ToString())); listRole.Add(role); } } return listRole; } catch (OleDbException ex) { throw new Exception("OleDb Error: " + "\n" + ex.Message); } catch (Exception e) { throw new Exception(e.Message); } finally { conn.Close(); } }
|
Thanks