Create new columns for matching keyword usinglinq

i have a table below

Name Dept comment
x IT also error
y IT not error
z ece yes
A CSE ok

output:I need two new columns to be created as “data 1 " and “data2” and values should be like
data1: if comment columns contains “Error” or " ok” then the value should be
verified.
data2:if dept contains IT or cse then the value should be “computer”

How can we achieve this with linq as this would have to address lakhs of records

 Dept    comment      data1                 data2
    IT         also error     verified             computer
    IT     not error           verified             computer
    ece       yes                no                     na
    CSE      ok                   verified           computer

Most easy way will be using “calculated” column using the “expression” comlum propperty

1/ Add two new columns to the DT - using “Add Data Column” activity.
2/ Define the expression propperty using “Assign” activity
dt.Columns("data1").Expression = "IIF(comment LIKE '*error*' OR comment LIKE '*ok*', 'verified','no')"
dt.Columns("data2").Expression = "IIF(Dept LIKE 'IT', 'computer','na')"

More about it in MS reference:
DataColumn.Expression Property (System.Data) | Microsoft Docs

Cheers

Thank you…Good info

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