How to build DataTable without using Build DataTable activity

I have a Extracted Datatable from website. Let say, Extracted datatable has 20 rows and i want to add only 10 DataRows into my New DataTable. Can i make this possible?. Can anyone help. :slight_smile:

@VenkatDurbha

Yes, You can. Try below expression to read first 10 rows from given input dataTable.

newDT = inputDataTable.AsEnumerable.Take(10).CopyToDataTable

2 Likes

Lets suppose, i have filter conditions which filters the values from the first dataTable and it only copy the values which satisfy the condition into new datatable. How can we do that?

Buddy @VenkatDurbha

you can use add data row activity to add the filtered datarow to a datatable you want
Buddy @VenkatDurbha

@VenkatDurbha

newDT = inputDT.Select("[ColumnName1] = ‘Value’ AND [ColumnName2] = ‘Value’ AND [ColumnName N] = ‘Value’…").CopyToDataTable

And also you can use Filter DataTable activity.

5 Likes

or you can use filter datatable activity and make the filter you want and the output will of datatable with rows you need buddy @VenkatDurbha

I have tried using that, but didn’t worked. I have using For Each Row activity and kept “Add DataRow” activity inside it. In DataRow am using “Row” which i get from For each Row activity. But i didn’t worked. :frowning:

1 Like

buddy mention in array row property and not in datarow property in add data row activity buddy @VenkatDurbha
and try to use for each loop with input as datatablename.Rows and change the type argument of the for each loop as datarow, instead of using for each row loop
and in add data row property with array row, mention like this buddy {item(0),item(1),item(2)}
where item is the variable obtained from for each loop activity and item is of type datarow which can be obtained by changing the type argument of for each loop as datarow and 0,1,2 are the column index buddy
Kindly try this and let know buddy whether this works or not
Cheers

were you able to get now buddy @VenkatDurbha

please help me with the exception.

can you help me with the exception.?

1 Like

buddy can i see the properties of add data row activity
mention the values in arrayrow property of add data row activity buddy
like this
{item(0),item(1),item(2),…)}
where item is the variable from for each loop and 0,1,2,…are the index of the column buddy
Cheers @VenkatDurbha

@VenkatDurbha

No need to use Add Data Row activity and all here. just check above posts of mine and try.

1 Like

If i don’t want to add specific columns and wanna to add specific rows to New DataTable, then what should i do??

1 Like

I don’t want to hard code the rows, as i want add specific rows based on the filter conditions which remove the rows and will only add the rows which satisfy the condition into new DataTable.

1 Like

Buddy we are not hard coding the rows here buddy
we are mentioning it as a array of row buddy, not the value
only if we mention the value explicitly like {“1”,“2”,“3”,…} it becomes hard coded
here we are passing them after validation as a array of row buddy
@VenkatDurbha

if i dont know the number of rows are there in the datatable then??.

1 Like

Buddy that must be if we dont know the number of columns in a row to be passed in array row property of add data row
fine
propably that we know only then we can create a datatable buddy, we might not know the number of rows in a datatable but only when we know the columns we need we can create a datatable buddy @VenkatDurbha

if i know all the columns need to be added into the new datatable, then what should i do?

1 Like

Fine, you can mention the column index of all the column in the array row value buddy
@VenkatDurbha

1 Like