locked
Error - Cannot implicitly convert type String to Employee_Management.GenderTye RRS feed

  • Question

  • User1979860870 posted

    Hi

     Error - Cannot implicitly convert type String to Employee_Management.GenderTye

    SqlDataReader rdr = cmd.ExecuteReader();
    
                    while (rdr.Read())
                    {
                        Employee Employee = new Employee();
                        Employee.Code = Convert.ToInt32(rdr["Code"]);
                        Employee.Name = rdr["Name"].ToString();
                        Employee.Gender = rdr["Gender"].ToString();
                       lstEmployee.Add(Employee);
                    }

    public class Employee
        {
            [Key]
            public int Code { get; set; }
     
            [Required(ErrorMessage = "Name Required")]
            [StringLength(50, MinimumLength = 3)]
            public string Name { get; set; }
     
            [EnumDataType(typeof(GenderType))]
            public GenderType Gender { get; set; }
        }

    public enum GenderType
        {
            Male,
            Female,
            Other
        }

    Thanks

    Friday, January 22, 2021 8:47 AM

All replies