Add datatable to an existing datatable

Hi All ,

I need to add a new datatable to an existing data table which has rows into it.
And i dont want to lose the old records in the datatable.

All the above actions are getting performed in a loop. So could anyone please help on this

Hi @vishal_nachankar ,

Are the datatable columns the same in the two datatables ? If so, You could use the Merge Datatables activity.

Let us know if this is not what was expected. Also, if possible provide us with the Inputs and the Expected Output data, so that we could provide the right suggestion.

I have used merge datatable activity but it is not working as expected.

Yes the columns are same in the both datatables.

Actually i am extracting the report from SAP for customers and storing it in the excel and then reading the excel and storing it in the final datatable

Read excel datatable is dtTemp and final datatable is dtfinal

@vishal_nachankar ,

Could you let us know more on what is not working as expected ?

for eg in first extract no of is 400
and in the next run the extract no of rows is 800

so it is only adding the 800 rows not as 800+400

this things are running in for loop.

@vishal_nachankar ,

Could you let us know How is this part done ? Is it inside the loop ? If so, then you would require to keep it outside and before the loop and check.

@vishal_nachankar

When you tried Merge datatable what was the issue you got?

Thanks,
Srini

what to keep outside the loop?

See i will explain:

For loop for customers
{
Extract the report from SAP and store in excel.
Read the excel and store in DT1
merge DT1 as source and destination value =final dT
clear the DT1
}
This above loop will extract the report for all the customers for eg Cust{1,2,3,4}

Suppose the no of rows for each customer are 100,200,300,400
So in the final DT should have 1000 rows but it is storing only last value

the issue is it only updating the last value which is stored in the datatable of the extraction

@vishal_nachankar ,

How is the Final DT created ?

@vishal_nachankar

You can try as below

Build a Datatable as FinalDT with headers

For Loop for Customers
{
Extract the report from SAP and store in Excel
}
now read the Excel and store to DT1
Merge that to finaldt

hope this may help you

Thanks,
Srini

means? what exactly you need

in the loop there are multiple customers for which reports are extracted and saved as temp file and then it read and stored in datatable and then it is merged in final datatable

@vishal_nachankar ,

At which Step is the Final DT created, meaning where it is initialised ? Do you have a Datatable with Columns set using Build Datatable activity ?

Final DT is the merging of the all the reports which are extracted in the loop.

Basically after Extracting the report the bot saves in temp excel and then reads the temp excel and store in DT1 and then use the merge activity were the source is DT1 and destination is FinalDT. once merged is done bot clears the DT1 and also deletes the temp file. so that in the next iteration it again extracts the report and perform the same steps but in while merging the records it is not considering the records which are in final DT

Before the Loop is started and now it doesnot have any columns created just i have provided a default value as new system.data.datatable();

@vishal_nachankar ,

If this is the case, then it should be working, unless the FinalDT is also been cleared when the DT1 is getting cleared.

You could Check by applying a Breakpoint at the Clearing of the DT1. Check in the Debug panel if alter clearing the DT1, the value of FinalDT also gets cleared.

final DT i am not clearing anywere

Thanks Buddy it is working…the datatable was get reinitiated as i was declaring it in default values

1 Like

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