Linq to update a column values if a specific value present

Hello everyone,

In a data table column ,lets say column 3 contains the value true and false,
image

Provide a LINQ query to update the values in column 3 from true to false.
required output
dt_Table
[Column1,Column2,column3
abc,1,false
efg,2,false
hijk,3,false
grwgwer,4,false
awfetg,5,false
fwegre,6,false

process created on C#

@krishna_r

You can directly do it using expression as below…use in assign

Dt.Columns(2).Expression = "'False'"

Cheers

Hi Anil,

Can you please explain in detail
Current process is in C#

Hi @krishna_r ,

Can you elabrate the query?

Regards,
Pavan Kuamr

@krishna_r

If C# use as below

dt.Columns[1].Expression = "'False'"

Here dt is the input datatable …1 is the column index…(Index starts from 0) …you can as well use column name instead of column index

Expression is used to set the value to whole of the column… As you wanted false to be set we are giving False between single quotes and the value should be a string so using double quotes around it

Hope this helps

cheers

Hi,

How about using Invoke Code as the following?

dt.AsEnumerable().ToList().ForEach(r=>
    {
        r["Column2"]="false";
    }
);

img20230105-1

Main.xaml (7.0 KB)

Regards,

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