Abhilash J A

Abhilash J A

  • 530
  • 2.4k
  • 598.4k

error: Specified cast is not valid.

Dec 7 2016 6:35 AM
Hello everyone,
 
After implement this code, 
 
  1. public class MainUserLogin  
  2.    {  
  3.        public Nullable<DateTime> LogInTime { getset; }  
  4.        public Nullable<DateTime> LogOutTime { getset; }  
  5.        public Int64 Id { getset; }  
  6.        public string FirstName { getset; }  
  7.        public string SurName { getset; }  
  8.    }  
  1. List< MainUserLogin> objUserSetUp = userList.Select(m => new  MainUserLogin()  
  2.                {  
  3.                    Id = m.Field<Int64>("Id"),  
  4.                    FirstName = m.Field<string>("FirstName"),  
  5.                    SurName = m.Field<string>("SurName"),  
  6.                    LogInTime = m.Field<DateTime?>("LogInTime"),  
  7.                    LogOutTime = m.Field<DateTime?>("LogOutTime")  
  8.                }).ToList();  
If LoginTime or LogOutTime is existing null then the error is happening "Specified cast is not valid."
How can I solve this error?
 

Answers (3)