类型' System.InvalidCastException'的例外情况发生在

时间:2016-05-04 18:30:30

标签: c#

我得到了以下模型:

public class ContentModels
    {
        public ContentModels(int _id, string _content, string _weight, string _language, string _country, string _location, string _os, string _browser, string _type, DateTime _startDate, DateTime _endDate)
        {
            id = _id;
            content = _content;
            weight = _weight;
            language = _language;
            country = _country;
            location = _location;
            os = _os;
            browser = _browser;
            type = _type;
            startDate = _startDate;
            endDate = _endDate;
        }

    public int id { get; set; }
    public string content { get; set; }
    public string weight { get; set; }
    public string language { get; set; }
    public string country { get; set; }
    public string location { get; set; }
    public string os { get; set; }
    public string browser { get; set; }
    public string type { get; set; }
    public DateTime startDate { get; set; }
    public DateTime endDate { get; set; }
}

我控制器中的以下代码:

ContentModels content = new ContentModels(
Int32.Parse(reader["id"].ToString()),
reader["content"].ToString(),
reader["weight"].ToString(),
reader["language"].ToString(),
reader["country"].ToString(),
reader["location"].ToString(),
reader["os"].ToString(),
reader["Browser"].ToString(),
reader["Type"].ToString(),
(DateTime) reader["startDate"],
(DateTime)reader["endDate"]
);

几乎应该查询我的数据库并根据模型创建一个新对象。我的数据库如下所示:https://i.gyazo.com/d9e69fecf0e2117397819a665c665e03.png

当我运行代码时,我收到以下错误:https://i.gyazo.com/bcc33a414f46df9906dc046fc714ef65.png

有人可以指出我的错误吗?

0 个答案:

没有答案