I have one excel file in which there are 10 Columns and I need to check with a condition if it was true I need to update the values in the D column using linq query? Can anyone help..?

Hello,

I have one excel file in which there are 40 Columns and based on certain conditions I need to update the values in the C, D columns
Can anyone help me to write Linq for each to update the values in multiple columns?

@ppr @Yoichi @NIVED_NAMBIAR

Hi @PRASHANT_GABHANE

What is the condition? Need more information to construct the LINQ.

I have another excel where the ID is stored.
I need to search the ID in the my input excel if the ID is found I need to update the column C, D as β€œFound”

Hi @PRASHANT_GABHANE ,

Hope below video will help you to achieve this task.

Thanks.

2 Likes
  1. make ID String Array
  2. loop datatable row
  3. check that ID String Array contains row’s ID Column value

refer below code

Dim dt_Code As DataTable = New DataTable(β€œtable1”)
dt_Code.Columns.Add(β€œid”, GetType(String))
dt_Code.Columns.Add(β€œvalue”, GetType(String))
dt_Code.Rows.Add({β€œ1”,β€œa”})
dt_Code.Rows.Add({β€œ2”,β€œb”})
dt_Code.Rows.Add({β€œ3”,β€œc”})
dt_Code.Rows.Add({β€œ4”,β€œd”})
dt_Code.Rows.Add({β€œ5”,β€œe”})

'ID String Array
Dim arr_ids() As String = dt_Code.AsEnumerable().Select(Function(r) r(β€œid”).ToString).ToArray

Dim dt As DataTable = New DataTable(β€œtable2”)
dt.Columns.Add(β€œid”, GetType(String))
dt.Columns.Add(β€œcheck”, GetType(String))
dt.Rows.Add({β€œ1”,β€œβ€})
dt.Rows.Add({β€œ3”,β€œβ€})
dt.Rows.Add({β€œ5”,β€œβ€})
dt.Rows.Add({β€œ7”,β€œβ€})
dt.Rows.Add({β€œ9”,β€œβ€})

For Each r In dt.Rows
r(β€œcheck”) = If(arr_ids.Contains(r(β€œid”)),β€œFound”,β€œNot Found”)
Next r

linq_check_result

1 Like

Hello @park363

Thank you for your reply,

I just want to achieve this using Linq.
With just one assign statement.

Thank you,
Prashant

Hi @PRASHANT_GABHANE

Try this

(From r In inputDT
Let s = If(otherDT.AsEnumerable.Select(Function (x) x(0).ToString).ToArray.Contains(r(0).ToString), "Found", "Not Found" )
Let a = r.ItemArray.Take(2).ToArray
Let b = a.Append(s).toArray
Let c = b.append(s).ToArray
Let d = c.Concat(r.ItemArray.Skip(4).ToArray).ToArray
Select outDT.Rows.Add(d)).CopyToDataTable
  • Assuming that the ID Column is the first column in both the excels.
  • C and D columns will have status values as Found and Not Found.
  • From the first 4 columns 1st column is of ID, 3rd and 4th of status, 2nd column and other 36 columns will remain as it is.
2 Likes

I have one excel file in which there are 10 Columns and I need to check with a condition if it was true I need to update the values in the D column using linq query?
Can anyone help…?

Hello @Sai_Pappu ,

As a best Forum practice, when you have a question, create a new post on the forum.

Best,
Charbel