PLEASE PROVIDE ME WITH THE LINQ QUERY>…
CAN YOU TELL ME THE LINQ QUERY TO COMPARE DT1 and dt2 and set the new column value to be “New” or repeted.
I could be wrong, but since you need to update a column with a new value, you will need to use atleast 1 loop for each table you need to update. If you didn’t need to update a value, then LINQ alone would work.
So, I think you can use a combination of LINQ and ForEach. - Note that ForEach loops have been improved to be much more efficient and use less resources. (like 10k rows only takes 1-2secs to loop through)
Here is an example:
If Not demo1.Columns.Contains("Status")
Add Data Column "Status
If Not demo2.Columns.Contains("Status")
Add Data Column "Status
ForEach row In demo1
Assign matchedRows = demo2.AsEnumerable.Where(Function(r) r("Name").ToString.Trim.Equals(row("Name").ToString.Trim) And r("Age").ToString.Trim.Equals(row("Age").ToString.Trim) And r("Place").ToString.Trim.Equals(row("Place").ToString.Trim) ).ToArray
Switch (Boolean): condition: matchedRows.ToArray.Count > 0
Case True:
Assign row("Status") = "Repeated"
ForEach rowMatched In matchedRows //TypeArgument DataRow
Assign rowMatched("Status") = "Repeated"
Case False:
Assign row("Status") = "New"
ForEach row In demo2.AsEnumerable.Where(Function(r) r("Status").ToString.Trim = "" ).ToArray //TypeArgument DataRow
Assign row("Status") = "Mitigated"
You can also use something like String.Join(","r.ItemArray) = String.Join(",",row.ItemArray) when comparing each column to check all columns more dynamically if desired.
I hope this helps get you in the right direction.
Like I said, if you need to change values in a datatable, I don’t think you can get away with not using a For each loop.
Use this Linq Query to compare two Data Table - (From a In ReadDT.AsEnumerable() Join b In OutputDT.AsEnumerable() On a(“Col1”).ToString() Equals b(“Col1”).ToString() select a).CopyToDataTable
This query will bring only the matched value of First Data Table. Get the count of the DT and perform a loop
Use a Assign Property as - WriteDT.Rows(0).Item(“Col3”) = “Repeated”, Similarly for New