carlor
February 19, 2024, 9:48pm
1
I’m trying to do a case insensitive Linq search in a DataTable and return the first row. For example the value in the DataTable could be “Apple”, but I need to match with “APPLE”, or “AppLE”, etc. I’m trying to use the following to return the first DataRow found:
dt.AsEnumerable().Select(Function(x) x(“Column0”).ToString.ToLower.Equals(strString.ToLower)).FirstOrDefault()
I’m using an Assign activity and assigning it to a DataRow. Unfortunately, I’m getting the following syntax error:
“Option Strict On disallows implicit conversions from ‘Boolean’ to ‘String’. The selected value is incompatible with the property type”
Any help would be greatly appreciated by this Linq-free developer
Thanks,
Carlo.
ppr
(Peter Preuss)
February 19, 2024, 9:52pm
2
(From d in dt.AsEnumerable()
Where d("Column0").ToString().ToLower().Trim().Equals(strString.ToLower)
Select r = d).FirstOrDefault()
ppr
(Peter Preuss)
February 19, 2024, 9:57pm
3
ensure also that the variable which receives the LINQ returned result is of DataType: DataRow
pikorpa
(Piotr Kołakowski)
February 19, 2024, 9:57pm
4
Hey @carlor
try this:
dt.AsEnumerable().FirstOrDefault(Function(x) x("Column0").ToString().ToLower() = strString.ToLower())
If you want to know something more about LINQ, I can recommend @ppr tutorials:
[HowTo] LINQ (VB.Net) Learning Catalogue - News / Tutorials - UiPath Community Forum
vrdabberu
(Varunraj Dabberu)
February 20, 2024, 1:04am
5
Hi @carlor
Try this:
matchingRow = dt.AsEnumerable().Where(Function(x) x("Column0").ToString().ToLower() = strString.ToLower()).FirstOrDefault()
matchingRow
is of DataType System.Data.DataRow
If you want to return boolean value then use the below syntax:
isDataRowFound = dt.AsEnumerable().Any(Function(x) x("Column0").ToString().ToLower() = strString.ToLower())
isDataRowFound
is of DataType System.Boolean
Regards
Hi @carlor
Try this:
dt.AsEnumerable.Where(Function(x) x("Column0").ToString.ToLower.Equals(strString.ToLower)).FirstOrDefault()
Hope it will helps you
Cheers!!
rlgandu
(Rajyalakshmi Gandu)
February 20, 2024, 5:10am
7
@carlor
YourDataRowVariable = dt.AsEnumerable().FirstOrDefault(Function(x) x("Column0").ToString().ToLower() = strString.ToLower())
carlor
February 20, 2024, 2:20pm
8
This worked! Thank you. Looks like I have some reading to do
Carlo.
ppr
(Peter Preuss)
February 20, 2024, 2:21pm
9
carlor
February 20, 2024, 2:24pm
11
This worked. I’m also flagging it as the solution because I like that it has FirstOrDefault to ensure I only get one. Plus you added the bonus boolean solution
Thank you,
Carlo.
1 Like
carlor
February 20, 2024, 2:25pm
12
This also worked. Looks like there were many ways to accomplish the same thing.
Carlo.
1 Like
system
(system)
Closed
February 23, 2024, 2:29pm
15
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.