Select first 25 rows in a datatable

I am trying to select the first 25 rows in a specific column in a data table to be used as input for a Type Into field. How can I get just the first 25 rows from the data table as a string?

getting the first 25 rows - returned as a list (of DataRows)
YourDataTableVar.AsEnumerable.Take(25).toList

Getting the first 25 column values as an array
YourDataTableVar.AsEnumerable.Take(25).Select(Function (x) x(YourColNameOrIndex).toString.Trim).toArray

Hello @karen.c.stewart4.civ

Maybe you can do as below.

Dt2=Dt1.AsEnumerable().Take(25).CopyToDataTable()

Then use output datatable activity to convert to string.

When you say …(Function(x)… am I supposed to put the column name in there in place of the x? So for me the column name is Vendor. So would I do (Function(“Vendor”)…?

YourDataTableVar.AsEnumerable.Take(25).Select(Function (x) x("Vendor").toString.Trim).toArray

For LINQ starting have a look here:

When I do that it gives me an error - Value of type ‘1-dimensional array of String’ cannot be converted to String. Any thoughts on what I am doing wrong?

as mentioned it will return an array of string. Just do following:

Assign activity
Left: arrValues | Datatype: String( ) - string array
Right side:
YourDataTableVar.AsEnumerable.Take(25).Select(Function (x) x("Vendor").toString.Trim).toArray

Assign activity:
strValues = String.Join(“|”, arrValues) it will flatten the array and seperate it with a pipe |

Thank you so much @ppr Peter! That worked great!!

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