Corresponding row in data table not working

Hello,

I have a string value and a data table. I would like to match the string value to a row in the data table, and retrieve that row.

Please note a similar post I have made to this exists, in which I have used this code to retrieve the corresponding row in the data table:

drCorrespondingRow = dtCorrespondingTab.AsEnumerable.Where(Function(x)x(“ColumnName”).ToString.Equals(strKeyArea)).FirstOrDefault

However I get this error:
image

I have attempted to use filter data table however this does not seem to work.

Any suggestions as to how I can edit the code above?

Thanks

Hi @E.T.S

Can you try below

drCorrespondingRow= dtCorrespondingTab.Select("ColumnName = '" & strKeyArea & "'").FirstOrDefault

@E.T.S
you could use the linq suggested above or simply use the filter data table option and select the first row from the filtered datatable. It will give you the same result what you are trying to achieve from linq.

Hi,

Thank you for your suggestion - using the above am I getting the following error:
image

Hi @E.T.S

try the below linq

dataTable.AsEnumerable().Where(function(row) row(“name”).ToString = “abc”).First()

replace “name” with your column name and “abc” with your desired value.

Hi,

Thank you for your suggestion.

I am getting the following error with the suggested method:
image