Datatable to String array


I got a datatable with 10 records say
33 upto 99, 10

I want to store 1st five records in a string with a word ‘or’ in between each record like
11 or 22 or 33 or 44 or 55

Help needed.

Hi @Robotics

Based on array index you can add the values in between

Ashwin S


Do these steps,

  1. Loop through the datatable
  2. Initialize a variable in the output index field
  3. Inside for each row, use if activity and check if the index is greater than 5
  4. If index is less than 5, use a string variable and assign activity as stringVariable = stringVariable + row(“column name”).tostring

Hope this is clear :slight_smile:

1 Like

First thing I would do is only select the first 5 records of the table. You can do this with: dt1.AsEnumerable.Take(5)

Then loop through those 5 and append the string like @HareeshMR mentioned

Hello @Robotics you can try below

Log message = String.join(" or ", (From rw in select x = rw("ColumnName").tostring).ToList))

1 Like

It is not necessary that the data inside the datatable will be in the form of 5 or 10 records. May be 1 record, 5 or 10, 6 or 12 etc records will be there.
Assume there are 12 records are there inside a DT
1 to 5 should be stored separately
6 to 10 should be stored separately
11 & 12 stored separately.

dataTable.AsEnumerable().[Select](Function(x) x(“Column1”).ToString()).Aggregate(Function(a, b) String.Concat(a, " or " & b))

I am using the below query to convert one column of my datatable to string array :

String array = (dt2.AsEnumerable().Select(Function(a) a(5).ToString)).ToArray

I need to convert mulitple columns (3 columns from the datatable into string array) using the above query, Please help