当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Using SQL Server 2008 TIME column in class declaration

问题描述:

I hope this makes sense, I am trying to store a SQL Server 2008 time(7) datatype in an object.

I am using the below to read the data into the object, but it is crashing out on the line

timeStart = reader.GetDateTime(reader.GetOrdinal("timeStart"))

Other than changing my database field to a datetime, can anyone advise on a solution

My class declaration is:

public DateTime timeStart { get; set; }

public DateTime timeEnd { get; set; }

SqlDataReader reader = command.ExecuteReader();

while (reader.Read())

{

Schedules sched = new Schedules()

{

Name = reader.GetString(reader.GetOrdinal("Name")),

timeStart = reader.GetDateTime(reader.GetOrdinal("timeStart")),

timeEnd = reader.GetDateTime(reader.GetOrdinal("timeEnd")),

IntervalMinutes = reader.GetInt32(reader.GetOrdinal("IntervalMinutes"))

};

schedules.Add(sched);

}

网友答案:

Per the documentation, you should be using the TimeSpan type and SqlDataReader.GetTimeSpan.

分享给朋友:
您可能感兴趣的文章:
随机阅读: