I use datatable.select() return selectdatatable, Then I write selectdatatable.copytoDataTable,but

I use datatable.select() return selectdatatable, Then I write selectdatatable.copytoDataTable,but does not work

exception: the source contains a detached dataRow that can not be copied to the Datatable.

Hey @sarah

Datatable.select will return you datarow array so to copy them into another datatable you should use ImportRow method.

You can search this on forum.

If still any problem will you face then let us know :slight_smile:

Regards…!!
Aksh

1 Like

Hi Sarah,

Datatable.Select() returns an array of datarows, lets assume - dtr_filteredRows. You can use dtr_filteredRows.CopyToDatatable() in the right side of assign activity and use another datatable on the left side of assign.

Hope this helps

Regards,
Amrita

5 Likes

thanks

Hi Amrita

Can you send me an example. I do not find CopyToDatable only CopyTo.
Thanks.

@Pupina check this please:
CopyToDatatable.xaml (9.6 KB)

It’s because intellisense doesn’t work for it. But if you just type CopyToDatatable, it will work without error.
More info about this in the link below:

3 Likes

Thanks Ovi!!! It works!!!

I only need to figure out how to include headers. I read range with addheaders.
I try with clone the original datatable, instead of new datatable.
Can you also help me with this?

I could do it. It is a simple property. thanks.

Well…I am doing everything as you said but still getting “Object reference not set to an instance of an object”. Please help me there.

Hi @ManuRaj,

You can provide new datatable() in the default value of data table variable.
Also refer,

1 Like

As I am using DataTable.Select(), it will give an array of datarows. So, assigning new datatable() as default value of data table variable will give error.

Try initializing the DataRow Array.