Sairam Soham

Sairam Soham

  • NA
  • 47
  • 28.5k

System.InvalidCastException: Specified cast is not valid.

Jan 21 2016 8:52 AM

Hello,

I have the following code for casting. I am getting an exception System.InvalidCastException: Specified cast is not valid.

Am I missing something?

vTime is a variable of type TimeSpan

deliveredKWH = Math.Abs(float.Parse(dsMeter.Tables[0].Rows[i]["Delivered (kWh)"].ToString()) - float.Parse(dsMeter.Tables[0].Rows[i + 1]["Delivered (kWh)"].ToString()));

iTime = Convert.ToInt32(Math.Abs(vTime.TotalMinutes));


Answers (2)