Comapring two data tables

HI i have two Data tables i have to see if values of a specific column are not equal while comparing two Data tables then it should send an email with those values (i.e store# = " " and price=" ")saying values can i do that i also have to send email wihen values are found .kindly help me


Step 1: Assuming you have your datatables, first compare the number of rows in each table. If the number of rows are not equal, you’ll know they’re definitely NOT the same.

Step 2: If they have the same number of rows, use a counter variable (say intCounter=0) and use a while loop with the condition intCounter<datatable1Variable.Rows.count. Proceed to Step 3.

Step 3: Now compare for a particular column: if(datatable1Variable.Rows(inCounter).item(columnName)=datatable2Variable.Rows(inCounter).item(columnName))

Step 4: If at any time the condition is false, you can send a mail with the values that don’t match.

@siddharth loop should check each row of 2nd data table while comparing specific column of data table 1 with data table 2 if values matched it reutrns that value and if not email is shoot out i need like this Can u help me in making a simple work flow

Please follow below steps-
Considering dtDatatable1 and dtDatatable2 as two datatables,

  1. Compare Data table rows, dtDatatable1.rows.count <> dtDatatable2.Rows.count
  2. If dtatables doesn’t contain matching rows, compare datatables
    (from dt1 in dtDatatable1.AsEnumerable() join dt2 in dtDatatable2.AsEnumerable() On dt1.Field(of Double)(“Column1”) Equals dt2.Field(of Double) (“Column2”) Select dt1)
  3. This will return you the array of datarows. If array has data, means there are matching records in the datatables.
    arrayDatarow.Length > 0 => matching records found
  4. Also check is matching record count equals original record count, if yes, there are no unmatched records
    dtDatatable1.rows.count = arrayDatarow.Length
  5. Convert array of datarows to datatable, dtCompareData = arrayDatarow.CopyToDataTable()
  6. Else, Get unmatched records from datatable1
    dtDatatable1.AsEnumerable().Except(dtCompareData.AsEnumerable(), DataRowComparer.Default).CopyToDataTable()
  7. Result of above step will be a datatable. You can loop through get required details to send email.

Hope this is helpful!

1 Like

Hey @goharmalik

Check it out an existing post and let me know :slight_smile:

Just change a bit datatype of column what you are having. and can check a sample in the above thread attachment.


1 Like