Specific cast is not valid in linq query when compare two tables
Problem
Error display in linq query "specific cast is not valid" at System.Data.DataRowExtensions.UnboxT`1.ValueField(Object value) at System.Data.DataRowExtensions.Field[T](DataRow row, String columnName)
LinqQuery give error
Code:
var query1 = (from x in table1.AsEnumerable()
join y in table2.AsEnumerable() on x.Field<int>("UnitCode") equals y.Field<int>("UnitCode")
where y.Field<decimal>("CurrentMeterReading") > x.Field<decimal>("CurrentMeterReading")
select new { UnitCode = x.Field<int>("UnitCode"), CurrentReading = x.Field<decimal>("CurrentMeterReading") }).ToList();
Details
When make debug the first data table tableReadingExcelsheet retrieve data from excel sheet .
second datatable readingfromInvoiceTablesql retrieve data from wahinvoice table in sql .
I need to get list of rows in excel sheet that have current reading less than
currentreading in wahinvoice table for same UnitCode then display in datagridview .
Code: