I'm creating an events crud app and am trying to connect the "time" of the event from my database to my code. The data type in the database format is Time(7) and the asp.net code is GetDateTime. I need it to be in a HH:mm format (not the seconds).
I've tried using the reader.GetDateTime but it keeps saying the Specified cast is not valid. Below is the error message and code..
System.InvalidCastException
HResult=0x80004002
Message=Specified cast is not valid.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
// create a new event and add to list.
EventModel events = new EventModel();
events.Id = reader.GetInt32(0);
events.StartTime = reader.GetDateTime(1);
returnList.Add(events);
}
}