DEFAULT VALUE IN THE ADD DATA COLUMN NEEDS TO BE UPDATED BASED ON IF CONDITION

Hi Team,
(@aksh1yadav, @arivu96, @KarthikByggari, @Karthick_Settu, @ClaytonM, @pathrudu, @PrankurJoshi, @Priya_Pandey, @Divyashreem, )
Please respond as your suggestions and approaches matters alot to me.

Currently I am working on the Datatables.
I am have two datatables (lets say dtA and dtB), and I need to compare these two datatables such that particular column(lets say row(1) ) from both dtA and dtB needs to be compared and the new data column (lets say “Status” column ) needs to be created such that based on the comparative result the “Status” column will be filled with the data, if comparison is successful write cell as “repeted” and if comparison is false write cell as “new”.

Now, let me tell you my approach into this:-

A) - > for dtA manipulation

add data column (default value)= “New”
for each row in dtA
for each row in dtB
if rowDTA(1) = rowDTB(1)
write cell into DTA(column- “Status” as “Repeted”) ----------(in this case, the default value “New” will be replaced by “repeted”)

B) - > for dtB manipulation

add data column (default value)= “New”
for each row in dtA
for each row in dtB
if rowDTA(1) = rowDTB(1)
write cell into DTB(column- “Status” as “Repeted”) ----------(in this case, the default value “New” will be replaced by “repeted”)

As mentioned the new column needs to be added into both the DTs and corresponding values need to be updated.

Now, in my approach i am finding difficulty that I cannot update the value in the Status column when the if condition is true.
Here if the condition is true, I want the defult value - “New”, to be updated as “repeted”

Please let me know how can this be achieved, also you can tell me another approach which might be better and more efficient.

Please help, this is urgent.

Thanks and Regards,
@hacky

Hi @hacky
I’m just answering this super quick, before I head offline for a while…

Seems like you could run dtA through a loop, match it up with dtB, then update both rows in the same loop, which essentially updates the data table. Then, you can write the tables back to Excel.

Maybe something like this, where arrMatched is an array of DataRows that are matched:

For Each activity: ForEach rowA in dtA
    Assign activity: arrMatched = dtB.AsEnumerable.Where(Function(rowB) rowB(1).ToString.Trim = rowA(1).ToString.Trim ).ToArray
    If activity: condition: arrMatched.Count > 0
        Assign activity: rowA("Status") = "Repeated"
        For Each activity: ForEach rowB in arrMatched //TypeArgument DataRow
            Assign activity: rowB("Status") = "Repeated"

Excel Scope: Write Range for dtA
Excel Scope: Write Range for dtB

So, to summarize:
—Loop through dtA
—Compare with dtB by using .Where() to Assign an array of rows that match
—If a comparison was found (.Count > 0)
-----then, Assign status to rowA
-----and, Loop through the array of rows that matched and assign status to rowB
—Output the updated data set to Excel if desired

There might be some improvements needed to this idea, because I didn’t think about it for long. I apologize for any mistakes.

Regards.
@ClaytonM

2 Likes

@ClaytonM,

Sounds good, I knew I could find an approach by your help.

Although, it would be great if you could [provide me with the sample xaml file.