Can you elaborate on what you are getting that’s not your desired result after trying the suggested line of code?
Essentially, you would assign the matched row to the current row in the ForEach, then assign the value of the matched row to the the column in that row.
However, you must also decide if you only want to assign that value in each of the matched rows (there could be duplicates) or only the First matched row or only the Last matched row.
I believe the suggestion was using FirstOrDefault() which would give you only the first row.
To match with all rows if there are duplicates, then use .Where() which I’m more used to implementing, but is used similarly.
matchedRows = macro.AsEnumerable().Where(
Function(r) r("Payment Mode").ToString.Trim.ToUpper = row("Payment Mode").ToString.Trim.ToUpper And r("Bank Name").ToString.Trim.ToUpper = row("Bank Name").ToString.Trim.ToUpper And r("RRN").ToString.Trim.ToUpper = row("RRN").ToString.Trim.ToUpper ).ToArray
(the reason you need the .ToString is because if you don’t it tries to match them as objects which won’t work because each row references to a different data table. Also, the .ToUpper is so it’s not case-sensitive)
Then you want to check if it found any matches with .Count
IF matchedRows.Count > 0
inside the IF, you can choose to only use the first, last, or all rows. To assign to all rows you would place a ForEach inside the IF, like so:
IF matchedRows.Count > 0
ForEach match In matchedRows //typeArgument: DataRow
Assign: row("Macro Name") = match("Macro Name").ToString.Trim
If you choose to only do the first match then you can just use the index, like matchedRows(0)
. Also, .FirstOrDefault() will probably work instead of .Where, so if you want to use that, and have issues, just let us know what errors you are getting.
Also, if you get errors on any of this, please let us know what it’s showing.
Regards.