That should work. You can also use other methods to change the comma but Replace would work too.
“Enumerable” is basically another word for “something that can be counted” and is used like a list or array. So when you do table.AsEnumerable you are essentially changing the table to a list of DataRows. ‘
Function(r)’ is basically just saying to declare a variable ‘r’ to be used only within the parentheses of that function. ‘r’ can be any character or word, for example you could also use ‘row’; but just make sure that the variable used can identify what it is representing like ‘r’ for row… and since it can only be used within the parentheses, you can use the same variable in the same line too like
.Where(Function(r) ).Select(Function(r) ) and so on, if you choose. Lastly, don’t use a variable name that will be conflicted with another existing variable name. For example, if you have a ‘For each row In table’ and you use ‘
Function(row)’ in some code then there would be a conflict since ‘row’ is an existing variable representing the DataRow in the For each so should not be used in .Where or .Select code.
Also, this type of expression is called a Lambda expression and there are many resources online to find out how all this all works and with examples. C# code is similar but instead of ‘
Function(r)’ you will see ‘
r =>’. You will also find that there are resources on LINQ expressions which are closer to something you would see in SQL queries. However, I consider LINQ and Lambda as the same because they offer the same benefits but just do it slightly differently.
For example, here is a LINQ version of the .Where() method:
(From r in table.AsEnumerable Where Convert.ToDouble(r("c2").ToString.Replace(",", ".").Trim) < 200 Select r).CopyToDataTable
So you might see something like that as well, which is basically the same. However, I prefer the other way and believe it’s easier to read or understand.
That is just some useful knowledge to add from a newbie to another newbie.
Anyway, let us know if you need further help.
It looks like from your response, it was working correctly since 82.23 and 150 are < 200. If you need to “change” the values in the table, you will need loop through each row and assign the adjustment. So, the .Where() is just being used to filter and compare values, but not to actually change the values.