How to Convert a Row or Column items of a DataTable into Array or List

There are some cases where we need to convert items present in a row or column of a DataTable into an Array.

1. To convert Row items into Array or List :

There are several method (such as LinQ Query, .Select method, filter activity or read row activity) available to filter and select the required row from a DataTable.

Once the required row is selected (store in SelectedRow) :
Use Assign acitvity
MyDataArray | DataType: Array(of String)

To Convert to Array :
MyDataArray = SelectedRow.Select(Function (x) x.ToString).ToArray()

To Convert to List :
MyDataList = SelectedRow.Select(Function (x) x.ToString).ToList()

2. To convert Column items into Array or List :

Use Assign acitvity
MyDataArray | DataType: Array(of String)

To Convert to Array :
MyDataArray = (From row in InputDT.AsEnumerable() Select Convert.Tostring(row(“ColumnName”)) ).ToArray()

To Convert to List :
MyDataArray = (From row in InputDT.AsEnumerable() Select Convert.Tostring(row(“ColumnName”)) ).ToList()

Happy Automation!!

Thanks & Regards,
Rohith

1 Like