Linq Query to update a column in excel based on conditions on other columns in same sheet

Hi All,

I have created a linq query to update a ‘status’ column based on some Input column being not zero & need to match months of two columns . Pls check this Linq Query & let me know where is the mistake:

I’m getting error as ‘Range variable name can be inferred only from a simple or qualified name with no arguments’

(From row In outputdt.AsEnumerable()
Let inputAmount = Convert.ToDecimal(row(“Input”).ToString())
Let endDateMonth = DateTime.ParseExact(row(“End Date”).ToString(), “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture).Month
Let month = DateTime.ParseExact(row(“last mnth”).ToString(), “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture).Month
Let Bonus = Convert.ToDecimal(row(“BONUS”).ToString())
Let remarks = If(inputAmount <> 0 AndAlso endDateMonth = month,
If(inputAmount = Bonus, “found”, “not found”),
“no input”)
Select row.Field(Of String)(“Emp code”),
row.Field(Of String)(“Emp name”),
row.Field(Of DateTime)(“first Mnth”),
row.Field(Of DateTime)(“last mnth”),
row.Field(Of Decimal)(“Bonus Amount”),
row.Field(Of Decimal)(“Input”),
row.Field(Of DateTime)(“Start Date”),
row.Field(Of DateTime)(“End Date”),

Use row(“Emp code”).ToString row(“Emp name”).ToString etc

I tried that , then its showing

“Range variable name cannot match the name of member of the ‘object’ class”

Take the () off the end of your .ToString expressions. You just do row(“Input”).ToString not row(“Input”).ToString()

CopyToDataTable will work when this extension method will be applied correctly

LINQ is not returning a DataRow / DataRow Collection
Selection of an anonymous object will not forward anything usable for the CopytoDataTable

(Assumption: Legacy, Not expected that this Behaviour is changed to Windows compatibility

Cross check