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.
1 Like

Kindly have a look on this thread

Cheers @smita.mobifly

1 Like

getting same error.

1 Like

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

2 Likes

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

1 Like

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()

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.