The context is shown below in the getGames() method.
I get errors on these lines:
dtGames.Rows[i]["playTime"] = (TimeSpan)dtGames.Rows[i]["playDate"];
dtGames.Rows[i]["playDay"] = (DayOfWeek)dtGames.Rows[i]["playDate"];
because the playDate column is a DateTime.
Here is my solution but I don't like it. What else can I do?
dtGames.Rows[i]["playTime"] =
Convert.ToDateTime(dtGames.Rows[i]["playDate"]).TimeOfDay;
dtGames.Rows[i]["playDay"] =
Convert.ToDateTime(dtGames.Rows[i]["playDate"]).DayOfWeek;
public DataView getGames()
{
DataTable dtGames = DAL.GetTable("Games");
DataColumn colItem;
colItem = new DataColumn("playTime",
Type.GetType("System.TimeSpan"));
dtGames.Columns.Add(colItem);
colItem = new DataColumn("playDay",
Type.GetType("System.DayOfWeek"));
dtGames.Columns.Add(colItem);
for (int i = 0; i <= dtGames.Rows.Count - 1; i++)
{
dtGames.Rows[i]["playTime"] =
(TimeSpan)dtGames.Rows[i]["playDate"];
dtGames.Rows[i]["playDay"] =
(DayOfWeek)dtGames.Rows[i]["playDate"];
}
dvwGames = dtGames.DefaultView;
Cache.Insert("Games", dvwGames);
return dvwGames;
} |