Specified cast is not valid

Nov 22 2007 6:26 AM

I use this Kind of code for retrieving the data from database.Data are successfully retrieved from database.But when i use this method it produce the error Specified cast is not valid .(Error line is marked as red.).

In the Variable Sun datatype is float.But I don't know why comes error in this line?

private static TimeEntry FillTimeSheet(IDataRecord myDataRecord)

{

TimeEntry myTimeSheet = new TimeEntry();

myTimeSheet.EmpId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("EmployeeId"));

myTimeSheet.EmpName = myDataRecord.GetString(myDataRecord.GetOrdinal("EmployeeName"));

myTimeSheet.Sun = (float)myDataRecord.GetFloat (myDataRecord .GetOrdinal ("sunday"));

myTimeSheet.Mon = myDataRecord.GetFloat(myDataRecord.GetOrdinal("monday"));

myTimeSheet.Tu = myDataRecord.GetFloat(myDataRecord.GetOrdinal("tuesday"));

myTimeSheet.Wed = myDataRecord.GetFloat(myDataRecord.GetOrdinal("wednesday"));

myTimeSheet.Thu = myDataRecord.GetFloat(myDataRecord.GetOrdinal("thursday"));

myTimeSheet.Fri = myDataRecord.GetFloat(myDataRecord.GetOrdinal("friday"));

myTimeSheet.Sat = myDataRecord.GetFloat(myDataRecord.GetOrdinal("saturday"));

myTimeSheet.Tot = myDataRecord.GetInt32(myDataRecord.GetOrdinal("totalhrs"));

return myTimeSheet;

}


Answers (3)