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 mismatched.how can i do that i also have to send email wihen values are found .kindly help me
September 25, 2018, 9:22pm
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
September 26, 2018, 2:15am
Please follow below steps-
Considering dtDatatable1 and dtDatatable2 as two datatables,
Compare Data table rows, dtDatatable1.rows.count <> dtDatatable2.Rows.count
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) 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 Also check is matching record count equals original record count, if yes, there are no unmatched records
dtDatatable1.rows.count = arrayDatarow.Length Convert array of datarows to datatable, dtCompareData = arrayDatarow.CopyToDataTable()
Else, Get unmatched records from datatable1
dtDatatable1.AsEnumerable().Except(dtCompareData.AsEnumerable(), DataRowComparer.Default).CopyToDataTable() Result of above step will be a datatable. You can loop through get required details to send email.
Hope this is helpful!
September 26, 2018, 5:04am
Check it out an existing post and let me know
Use Below Code to Compare 2 Datatable Column and Get Matched and Not Matched Records
Note- Based on your datatable column datatype update datatype here with column field.
To Get Matched Records
Datatable Out_Matched_Data = In_DataTable1.AsEnumerable().Where(function(row) In_DataTable2.AsEnumerable().Select(function(r) r.Field(Of Int32)(In_DT2_ColName_To_Match.ToString)).Any(function(x) x = row.Field(Of Int32)(In_DT1_ColName_To_Match.ToString))).CopyToDataTable()
To Get Not…
Just change a bit datatype of column what you are having. and can check a sample in the above thread attachment.