Case Insensitive Linq search help

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 :slight_smile:

Thanks,

Carlo.

(From d in dt.AsEnumerable()
Where  d("Column0").ToString().ToLower().Trim().Equals(strString.ToLower)
Select r = d).FirstOrDefault()

ensure also that the variable which receives the LINQ returned result is of DataType: DataRow

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

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 :slight_smile:
Cheers!!

@carlor

YourDataRowVariable = dt.AsEnumerable().FirstOrDefault(Function(x) x("Column0").ToString().ToLower() = strString.ToLower())

This worked! Thank you. Looks like I have some reading to do :slight_smile:

Carlo.

Perfect, so the topic can be closed
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

This worked too!

Thank you,

Carlo.

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 :slight_smile:

Thank you,

Carlo.

1 Like

This also worked. Looks like there were many ways to accomplish the same thing.

Carlo.

1 Like

Another one that worked.

Thank you,

Carlo.

You’re welcome @carlor

Happy Automation!!

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