Linq Query to Update a column depending on the value of another column

Hi,
I have a scenario where i need to check a column consider vendor number, then if Vendor is either of 1111,2222,3333,4444,5555 or 6666 i need to update a new column status as Exact else i need to update Not Exact kindly help me with this scenario

Hi @Amrutha.mg ,
You can see

but I think you can activity
regards,

i need to check a single column in one datatable and update the same datatable

To easy understand I think can use activity
Or you can see of Mr.Peter

Hi,

How about the following sample?

dt.AsEnumerable.ToList.ForEach(Sub(r)
If arrTarget.Contains(r("vendor").ToString) Then
    r("status")="Exact"	
    Else
    r("status")="Not Exact"		
    End If
End Sub)

Sample20230829-1L.zip (8.4 KB)

Regards,

1 Like

@Amrutha.mg

Create an array like below

Arr_values={“1111”,“2222”,“3333”,“4444”,“6666”}

Use for each row in datatable

Place if activity

condition as

Arr_values.any(Function(×) x.conatins(currentrow(“Vendor”).tostring))

Gives you boolean output

Then assign
Currentrow(“status”)=“exact”

Else
Currentrow(“status”)=“notexact”

Cheers

Cheers

Hi @Amrutha.mg

Follow the below process steps
=> Read Data from Source into DataTable dtVendorData
=> Create an array

- Assign -> VendorNumbersArray = {"1111", "2222", "3333", "4444", "6666"}

=> For Each Row in dtVendorData

  • Get Vendor Number from Current Row
  • If Array.IndexOf(VendorNumbersArray, Vendor Number) >= 0
    • Set Status as “Exact”
  • Else
    • Set Status as “Not Exact”
      => Write Updated DataTable dtVendorData back to Source

Hope it helps!!

Thank you this worked

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.