猿问

为什么这个字符串不是日期

我不明白我在哪里犯了这个错误 System.FormatException: 'String was not recognized as a valid DateTime'


UserDOB 工作正常,但 DateTimeStamp 不工作。


while (reader.Read())

{

    list1.Add(new User()

    {

        UserId = Convert.ToInt32(reader["UserId"]),

        UserName = reader["UserName"].ToString(),

        UserSurname = reader["UserSurname"].ToString(),

        UserPassportNo = reader["UserPassportNo"].ToString(),

        UserAccessPoint = reader["UserAccessPoint"].ToString(),

        UserAccessType = reader["UserAccessType"].ToString(),

        UserDOB = DateTime.Parse(reader["UserDOB"].ToString()),

        DateTimeStamp = DateTime.Parse(reader["DateTimeStamp"].ToString()),

    });

}

我的model.DatabaseConnection


public class User

{

    public int UserId { get; set; }

    public string UserName { get; set; }

    public string UserSurname { get; set; }

    public string UserPassportNo { get; set; }

    public string UserAccessPoint { get; set; }

    public string UserAccessType { get; set; }

    public System.DateTime UserDOB { get; set; }


    //[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]

    public System.DateTime DateTimeStamp { get; set; }

}


慕的地6264312
浏览 124回答 1
1回答
随时随地看视频慕课网APP
我要回答