Getting a Specific value from Datatable without using For Each loop

How can we get the value in colum ‘n’ inside a datatable without using a for each loop? Let’s say i need to get the value ‘Rob’ in the table below.
What i have tried is using myDT.select(“Key=‘Name’”) and use For Each to the returned dataRow and use get row item activity to extract the value.
I have around 600 rows and i dont want to create 600 For each loops. Is there any other way of dealing this?

Key Value

Name Rob
BirthDate 11/01/2000
… …

Thanks in advance.

1 Like

Hi there @JGuarino,
You can use the select expression to return DataRows that match a given criteria, such as Name.

The attached example demonstrates this.

Please let me know if further clarification is required.
Josh

SelectTest.xaml (9.6 KB)

Thanks @Mr_JDavey for responding and for the sample solution, I appreciate the effort.
However, that is similar to what I was trying.

What I want to know is if it possible to get the value without using any “For Each” loop at all.
Like get the value of “Name”, (pseudo) myDT.select(“Key =‘Name’”)(row)(col).ToString.

Or can I directly access the value inside a DataRow without using a loop? Let’s day dRow(0)(1)?

1 Like

I already found the answer.
It took me some trial and error, I’m not sure if this is an efficient way but it is working and most importantly it is a one liner.
Of course we can access inside a Datatable using indexes such as myDT.Rows(0).Item(1).ToString,
but when using a search criteria such as SELECT inside a DataTable, we can use

myDT.Select(“Key=‘Name’”)(0).Item(1).ToString

Cheers Everyone!

4 Likes

Hi there @JGuarino,
Congratulations on finding the answer!

Apologies, I’d misunderstood the issue.

Have a fantastic day.
Josh

Can you replace the ‘Name’ in (“KEY=‘Name’”) with a variable when using .Select…?

Dawn

Hi Dawn,

Yes, you can have
myDT.Select(“Key=‘" + strName + "’”)(0).Item(1).ToString