Compare 2 datatables

Hi,
I have two datatables,i want to check if value of first datatable exist in 2nd datatable,the values in datatable are not same order,Please help

Hi @msalesforce777, would e.g. any of the below threads help you?


You can use the for loop to do the comparison.

OPTION 1:-

for each row1 in dt1

for each row2 in dt2

if (row1(“Column Name”).tostring = row2(“Column Name”).tostring)
{take actions}

OPTION 2:-
Use LINQ

OPTION 3:-

USE join

Hi @msalesforce777,

Please check this zip.file

Compare2_datatable.zip (29.5 KB)

First read both datatable and pass the datatable in 2 FOR EACH ROW and inside the body use if activity and in conditon pass row1("column name’).tostring = row2(“column name”).tostring

cool
Regards,
Gulshiyaa

If you find it useful mark it as solution and close the thread.

@msalesforce777,

what does it mean?

Can we compare data in random format.

image

sure

as datatable’s do not have column name defined

okay after comparing what you want?

Number of row (DataTable1) matched with data in DataTable 2

okay if matached? next process

Count of data matched should be displayed in message box

Any Solutions???

Hi @msalesforce777,

  1. Kindly use following linQ code in Assgin activity to get datatable having matched rows.
MatchedDT (DataTable) = Dt1.AsEnumerable().Where(Function(row)  Dt2.AsEnumerable().
Select(Function(r) (r.Field(Of String)(0)).Trim).Any(Function(x) x = (row.Field(Of String)(0)).Trim)).
CopyToDataTable()

here,
MatchedDT —> DataTable variable.
I’ve used (0) as index of the coulmn.

  1. Once you have filtered datatable having only matched rows, then getting count of rows be easy with .Count method as shown below.
MatchedDT.Rows.Count

Thanks for help

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