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; } }
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(); } }