Linq Query To Get Mismatch Rows

Hello Everyone,
image
DT1
image
DT2

I want to get the mismatch rows of “NAME” Column AND if no Mismatch i want to get empty Datatable

Hi @Prateek_Gulab_Pathak

use the below syntax

DT.AsEnumerable.Where(Function(x,i) not x(“Name”).ToString.Equals(DT1(i)(“Name”))).CopyToDataTable

cheers!

@Prateek_Gulab_Pathak

Try this LinQ

DTMismatch = (From row1 In DT1.AsEnumerable()
            Join row2 In DT2.AsEnumerable() On row1("NAME").ToString() Equals row2("NAME").ToString() Into matchedRows
            Where Not matchedRows.Any()
            Select row1).CopyToDataTable()

Hi @Prateek_Gulab_Pathak

Try this:

result = (From row1 In DT1.AsEnumerable()
          Join row2 In DT2.AsEnumerable() On row1.Field(Of Integer)("Name") Equals row2.Field(Of Integer)("Name") Into Group
          From g In Group.DefaultIfEmpty()
          Where g Is Nothing OrElse Not row1.ItemArray.SequenceEqual(g.ItemArray)
          Select row1).CopyToDataTable()

result is of DataType System.Data.DataTable

Hope it helps!!

Hi ,

you can try like this.

dt = Build Datatable

for each row in DT1
{
If( not dt2.AsEnumerable().Any(function(x) x(“Name”).ToString = Currentrow(“Name”).ToString))
{
Add Datarow(Currentrow.ItemArray) to dt
}

}

image
so many errors

this errors is showing in the assign activity

@Prateek_Gulab_Pathak

What is the error you are getting

Regards

image

@Prateek_Gulab_Pathak

Try this:

result = (From row1 In DT1.AsEnumerable()
          Group Join row2 In DT2.AsEnumerable() On row1.Field(Of Integer)("Name") Equals row2.Field(Of Integer)("Name") Into Group
          From g In Group.DefaultIfEmpty()
          Where g Is Nothing OrElse Not row1.ItemArray.SequenceEqual(g.ItemArray)
          Select row1).CopyToDataTable()

Regards

image
output is same as input

@Prateek_Gulab_Pathak

dt1.AsEnumerable.Where(Function(a) not dt2.AsEnumerable.Any(function(b) b(0).ToString.Equals(a(0).ToString))).ToArray

try this output is array of datarow

use if activity

1 Like

@Prateek_Gulab_Pathak

It seems you don’t have common columns between dt1 and dt2.

Regards

i have already provided the sample data it is same nothing changed and i want the Not Matched Row Or Empty Table If there is no Not Matched Rows

Hi @Prateek_Gulab_Pathak

Try this:

DT1.AsEnumerable().Where(function(row) Not DT2.AsEnumerable().Select(function(r) r("Name").ToString).Any(function(x) x = row("Name").ToString)).CopyToDataTable()

DT1
image
DT2
image
Output Result
image

Hope it helps!!
Regards

image
this error is showing if there are no Mis matched Column

Hi @Prateek_Gulab_Pathak

Check out this zip file
BlankProcess7.zip (131.8 KB)

This will print an empty data table if DT1 and DT2 have matching rows.

Hope it helps!!

1 Like

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