Specified cast is not valid while compare two datatable

Hello guys,
I am getting error while compare two data table using following query.

dt1.AsEnumerable().Where(function(row) dt2.AsEnumerable().Select(function(r) r.Field(Of Int32)( colname.ToString)).Any(function(x) x = row.Field(Of Int32)( colname.ToString))).CopyToDataTable()

.

wanted to automate following Scenario

  1. Read first file having some rows and columns
  2. Read second file having some rows and columns
  3. compare both data table and select only unmatched rows[ which is not common]
  4. write range with unmatched rows into result file.

Kindly have a look on this thread

Cheers @smita.mobifly

getting same error.

Kindly try with this expression
dt1.AsEnumerable().Where(function(row) dt2.AsEnumerable().Select(function (r) convert.ToInt32(r(colname.ToString)).Any(function(x) x = Convert.ToInt32(row(colname.ToString))).CopyToDataTable()

Cheers @smita.mobifly

thanks issue resolved, change type from int32 into string.

Awesome
Cheers @smita.mobifly

hi @Palaniyappan,

hi its work for matched record but dint work for not matched.
getting source contains no data Rows

solved, just change place of datatable into query,
In_DataTable2.AsEnumerable().Where(Function(row) Not In_DataTable1.AsEnumerable().Select(Function(r) r.Field(Of String)(colname.ToString)).Any(Function(x) x = row.Field(Of String)(colname.ToString))).CopyToDataTable()