How to convert array of string to Data table

This is my current table array:

image

But I need convert into data table with header “Column1”

Please :pray:

Thanks
Shaik

@shaik.muktharvalli1

Use build data table and create a column

arr.Select(Function(a) dt.Rows.add(a.ToString)).copytodatatable
2 Likes

@shaik.muktharvalli1,

You can achieve the conversion from an array of strings to a DataTable using the Invoke Method activity with the DataTable class’s LoadDataRow method. Here’s how you can do it without using a loop:

  1. Initialize DataTable: Use the ‘Build DataTable’ activity to create an empty DataTable with the desired structure.
  2. Convert Array to DataRow Array: Use the Select method on the array of strings to convert it into an array of DataRow objects.
  3. Invoke Method to Load Data: Use the Invoke Method activity to call the LoadDataRow method of the DataTable. This method will load the DataRow array directly into the DataTable.

Thanks,
Ashok :slight_smile:

can you provide invoke method please

thanks
shaik

Hi @shaik.muktharvalli1 ,

Step 1 : Use Build Data Table activity and set the header ‘Column1’ and Output in Properties pane to the Data Table Variable

Step 2 : Use an Assign Activity,

LHS : Data Table Vaiable (eg: dt_SampleTable)
RHS : (From x in StringArray Select r = dtResult.Rows.Add(new Object(){x})).CopyToDataTable

Or Method syntax:
stringArray.Select(Function (x) dtResult.Rows.Add(new Object(){x})).CopyToDataTable

Hope this helps you.

Happy Automating…!

if this helps you get the desired result, Please mark this as a solution.

Thanks,
Gautham.

@shaik.muktharvalli1,

Sorry don’t have studio on current machine but this is how you should configure the Invoke method.

Invoke Method activity:

  • TargetObject: dtStringData
  • MethodName: LoadDataRow
  • Parameters:
    • Parameter: dataRows

Thanks,
Ashok :slight_smile:

Columnname can be adapted afterwards as well

Assign Activity
dtVar.Columns(0).ColumnName = "Column1"