LINQ query for update column

Hi all,
I am using: “dt_AmountList.AsEnumerable().Select(Function(row) If(row.Field(Of Integer)(“Age”) < 30, row.SetField(“Type”, “Minor”), row)).CopyToDataTable()”. However, I am getting an error. Please, anyone suggest what mistake I made?

@JK_MECH,

It’s not tested but try this.

dt_AmountList.AsEnumerable().Select(Function(row)
    If row.Field(Of Integer)("Age") < 30 Then
        row.SetField("Type", "Minor")
    End If
    Return row
End Function).CopyToDataTable()

What’s the error you are getting?

Hi @JK_MECH

dt_AmountList.AsEnumerable().Select(Function(row)
                                      If(row.Field(Of Integer)("Age") < 30, 
                                         row.SetField("Type", "Minor"), 
                                         Nothing)
                                      Return row).CopyToDataTable()

Hope it helps!!

no madam,it is not working

i tried to use above expression sir, and i am getting error like “Statement lamdas cannot be converted to expression trees”

@JK_MECH,

Ok use this one in Invoke Code. It’s tested.

dt_AmountList = dt_AmountList.AsEnumerable().Select(Function(row)
    row("Type") = If(Convert.ToInt32(row("Age")) < 30, "Minor", row("Type"))
    Return row
End Function).CopyToDataTable()

Argument should be In/Out direction.

Output:

1 Like

thank you very much sir

1 Like

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