Compare two column and update to another column through linq

linq.xlsx (8.3 KB)
Hello All,

I want to write linq query to check two column Col A and Col B "If Col A contains “Needed” and col B contains “TRUE” then update to Col c = “Present” else remaining are same as it. Please help me to find the solution.

Hi,

Hope the following sample helps you.

img20210611-2

dt = dt.AsEnumerable.Select(Function(r) dt.Clone.LoadDataRow({r("Col A"),r("Col B"),if(r("Col A").ToString.Contains("Needed") AndAlso r("Col B").ToString.ToUpper="TRUE","Present",r("Col C"))  ,r("Col D")},False)).CopyToDataTable

Sample20210611-2.zip (8.4 KB)

Regards,

2 Likes

Thank you for your Help. Sample has work for me.

1 Like

@Yoichi
In the same sheet i want to update the datatable
ex: i have some 10 coulmns.
Out of that i have to check columns -“Names” and “Material” should not be nothing
then update the columns column(“status”)=“Approve” and column("Date ")=Date.Now

want to create a new datatable at last

Please help
Regards,
Seema

the code i wrote is half done

from a In DT1.AsEnumerable()
If(a.Field(Of String)("Name")<>"",Nothing)} ANDa.Field(Of String)("Material")<>"",Nothing )) 

now next part updating how to perform

Hey use my package :slight_smile: Power Search Activity - RPA Component | UiPath Marketplace

@Mikolaj_Zielinski

how to download it?
i want lastly the o/p to be same datatable with udated values…
but i see you have used List

Uipath → manage package and look there or download it from the marketplace as file and in manage packages add a new directory to look for packs and you can install it like this.

This method was more useful for me when I designed it :slight_smile:

Hi rayan,

we can do it by writing a LINQ query
that is

take another data table and clone it from original

dt2 =dt1.clone

(from d in dt1.asenumerable
let x= if( d(0).tostring.tolower.contains(“needed”) AndAlso d(1).tostring.tolower.contains(“true”), “TRUE”,Nothing)
let y= new object(){ d(0),d(1),x,d(3)}
select dt2.rows.add(y)).CopyToDataTable

this will work definitely

cheers…!!!