STORING DATATABLE (having only one column) info into the string ARRAY...?

Hi @teamMolly.

I am stuck, it is about storing the datatable variables into the string array variable in the particular fashion.

So I am having a excel sheet(or datatable) which consist of only the computer server names.
eg:- Server A, Server B, etc…

Like suppose there are 100-200 server names in this excel sheet(or datatable).

Now, I need to make sure that I am able to retrieve all these server names in a string array variable:-

strArray1 = " ‘Server A’, ‘Server B’, ‘Server C’, ‘Server D’, ‘Server E’, ‘Server F’ "

Please help me creating this logic where strArray1 has all the server names in the above fashion.

Thanks and Regards,

if your server names are in a column, then you read range, and with the DT extracted, you use a For each row, in the for loop you just add to your string the new server name

strArray1 = strArray1 + DT.item(0).toString


please elaborate the strArray1 part.

I am very much aware of the read range and retrieving the value in the DT followed by using for each row.

I am just not sure how do I add the server names to the string array in the desired pattern.:
" ‘Server A’, ‘Server B’, ‘Server C’, ‘Server D’, ‘Server E’, ‘Server F’ "

Please note the double quotes and single quotes and the coma separations.

Since the column in the datatable will be as follows:-

Server Name
Server A
Server B
Server C
Server D etc

And the desired output is :- " ‘Server A’, ‘Server B’, ‘Server C’, ‘Server D’, etc"


Once you have a excel data in the Data table say dt, follow the below steps

strArray → a string variable

For each item in dt
strArray = strArray + “’” + item(0).ToString + “’” + ", "

After the loop,
strArray = strArray.Substring(0,strArray.Length-2)


Thanks alot, this makes sense.

But then again I need some other output. Kindly note the below differnece between need output and output that I get in your suggesion:-

What output is comming:- ‘Server A’, ‘Server B’, ‘Server C’,

Desired output :- " ‘Server A’, ‘Server B’,‘Server C’ "

Please help me get the double quotes in the final output.

Can you check this -

strArray = “”"" + strArray.Substring(0,strArray.Length-2) + “”""


It is showing an error, object reference not set.
Please help.