Datatable extract to assign variable to get all columns

Hi everyone

Below is my test extraction for my datatable table extract.

I am trying to get the number at column = “Column-1”.

I tried using variable.

X = DT.Rows(3)(2).Tostring

But I this method will only get the number “9123817”
My desire output is to get all the number in “Column-1” for row 3,4,5 and so on.
I dont need the row at position 0,1,2.

How to do I assign a variable for to get all that number?
Or is there a better and simpler method for that?

Hi @Irfan_Musa ,

We would also ask in what format you would require the values. Do you need it as a String or as an Array of String ?

For Array of String Output :

column1Values = DT.AsEnumerable.Skip(3).Select(Function(x)x("Column-1").ToString).ToArray

Here, column1Values is of the type Array of String.

For String Output :

column1ValuesStr = String.Join(",",DT.AsEnumerable.Skip(3).Select(Function(x)x("Column-1").ToString).ToArray)

Here, column1ValuesStr is of type String.

hi @supermanPunch , may I know what is array of string? is it like a list of the string?

For me I just want to save it to excel as string and it should occupy the column in my excel template (just like in the datatable).

@Irfan_Musa ,

To avoid further confusions, could you let us know what is the Output format required ? If it is to be stored in Excel sheet, let us know the Expected Output format as to how it should be stored or presented. Screenshots of the Output format would be helpful.

We could then better identify the requirement for your case, and suggest appropriate solution.

Hi @supermanPunch

I used add data row activity in the
ArrayRow: {NO,name}
output as DT_Data_Output
Then I write to the excel template sheet

The number should occupy below the column “NO” of excel sheet “Data_Output_Test”

image

Desired output is per below:
image

@Irfan_Musa ,

Could you let us know what is the name value and how is it related to number or what is the source of name value?

We could just use the below Expression in Write Range activity :

DT.AsEnumerable.Skip(3).CopyToDatatable.DefaultView.ToTable(false,"Column-1")

image

But we do also see the name value being used, so we need to know the relation between the NAME and NO columns, so that the co-relation is maintained.

@supermanPunch for the column “NO” is where I want the number to be fill, there is another column “Column-2” in the table extraction where I want to write in the excel template where the column name is “NAME”. Where I can just use the same method to get the “NO”

@Irfan_Musa ,

From your statements understanding that the Column-2 is the Name value, then you could use the below Expression to get the Required data in the column order required and then use Write Range activity :

DT.AsEnumerable.Skip(3).CopyToDatatable.DefaultView.ToTable(false,"Column-1","Column-2")

Just use the Expression as shown in the Image and let us know if it works :
image

Hello @Irfan_Musa

Assign activity:
To: yourVariable (e.g., NumbersList)
Value: Enumerable.Range(2, DT.Rows.Count - 2).Select(Function(i) DT.Rows(i)(1).ToString).ToList()

Thanks & Cheers!!!

Hi @Irfan_Musa

please use for each row in datatable activity.
use below expresion:
datatable variable = currentrow(“Column name”).tostring

Hi @supermanPunch thank you this solution helps. Thank you so much for you help

Hi @Kartheek_Battu thank you for the help! I appreciate it. Will keep this in my notes

Hi @Vinayak_Kapse thank you for your help! I appreciate it and will keep this in my notes !

Hi @Irfan_Musa,

Has you problem been solved?

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.