I can not understand why "Specified cast is not valid exception" is thrown here:
c# code:
the exception throws when it reaches to m.HadapGoalPercent
property, i tryed to change the datatype of x => x.Field<float>("HadapGoalPercent")
also to single and double but its not working
for (int i = 0; i < dt.Rows.Count; i++)
{
Sales.Month m = new Sales.Month(Yearnum, (byte)(i+1));
m.HadapGoal = dt.AsEnumerable().Where(x => x.Field<int>("MonthNum") == i + 1).Select(x => x.Field<int>("HadapGoalIncome")).Single();
m.ShotefGoal = dt.AsEnumerable().Where(x => x.Field<int>("MonthNum") == i + 1).Select(x => x.Field<int>("ShotefGoalIncome")).Single();
m.HadapGoalPercent = dt.AsEnumerable().Where(x => x.Field<int>("MonthNum") == i + 1).Select( x => x.Field<float>("HadapGoalPercent")).SingleOrDefault();
m.ShotefGoalPercent = dt.AsEnumerable().Where(x => x.Field<int>("MonthNum") == i + 1).Select(x => x.Field<float>("ShotefGoalPercent")).SingleOrDefault();
months.Add(m);
}
thats the definitions of ShotefGoalPercent
and HadapGoalPercent
properties inside Month Class:
public Single ShotefGoalPercent { get; set; }
public Single HadapGoalPercent { get; set; }
thats dt datatable:
(HadapGoalPercent and ShotefGoalPercent are defined as decimal(5,4) in sql database)
thank you very much for your time and considiration