コード例 #1
0
        public List <RolesDO> ViewAllRoles()
        {
            List <RolesDO> allRoles = new List <RolesDO>();

            try
            {
                using (SqlConnection roleConn = new SqlConnection(roleConnectionString))
                {
                    SqlCommand enterCommand = new SqlCommand("READ_ROLES", roleConn);
                    enterCommand.CommandType = CommandType.StoredProcedure;
                    roleConn.Open();

                    DataTable roleInfo = new DataTable();
                    using (SqlDataAdapter roleAdapter = new SqlDataAdapter(enterCommand))
                    {
                        roleAdapter.Fill(roleInfo);
                        roleAdapter.Dispose();
                    }

                    foreach (DataRow row in roleInfo.Rows)
                    {
                        RolesDO mappedRow = MapAllRoles(row);
                        allRoles.Add(mappedRow);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(allRoles);
        }
コード例 #2
0
        public RolesDO MapAllRoles(DataRow dataRow)
        {
            RolesDO roles = new RolesDO();

            try
            {
                if (dataRow["RoleID"] != DBNull.Value)
                {
                    roles.RoleID = (Int64)dataRow["RoleID"];
                }
                roles.RoleName = dataRow["Name"].ToString();
            }
            catch (Exception ex)
            {
                throw;
            }
            return(roles);
        }