Converting Data Table to an Array of String

I am having of a list of items in an excel which I want it in a string array. After reading the excel data using read range, how do I use the assign activity to convert the datatable data to my string array? I saw many similar discussions in the forum but it did not work properly for me. Please help me out on this. Thank you

@risheviswanath_s you can use something like this:

stringArr = dataTable.Rows[0].ItemArray.Select(x => x.ToString()).ToArray();

stringArr is type of String Array

Note: It will convert the first row to Array of String type because I have given 0 in the syntax.

Hope it will help you.
Best!!
Anmol

@anmolk171 thanks for the reply. May I know where exactly I need to type this out. By typing this, suppose my string array name data_list then how will the content of the data table be converted and stired in the string array since the varaible name of string array is not mentioned.

@risheviswanath_s
you will create a variable with the name as you want (for explanation i will use stringArr) and set it to datatype String() (an array of strings)

within an assign activity

  • on the left side(To) - stringArr
  • on the right side - dataTable.Rows(0).ItemArray.Select(Function (x) x.ToString().Trim).ToArray()

dataTable is to replace with the variable name that you have used for the datatable in your implementation

Result: a string array of all column values from the first datatable row

1 Like

@risheviswanath_s - I guess @ppr write the way to do that.

I have done the same but i get this error. Ledger_list is the name of my string array.

@risheviswanath_s
there was a copy and paste typo. try this:
dataTable.Rows(0).ItemArray.Select(Function (x) x.ToString().Trim).ToArray()

1 Like

Hey @ppr
I just tried and it is working but when I display the output of the string array in a message box using for each activity, only the first line of the table is getting printed. So i guess the other line items from the data table have not been converted and assigned to the string array. Thanks

@risheviswanath_s
Rows(0) is doing this for the first Row only. Please reformulate your requirement with other words or share a colored image showing on what all should go into the array. Thanks