How to resolve CopyToDataTable is not a member of the System.Data.DataTable?

Hello Good People,

Am getting the error of CopyToDataTable is not a member of System.Data.Datatable.
I read through the different articles and they were advising that I should add

<AssemblyReference>System.Data.DataExtensions</AssemblyReference>

but it is already available as shown in the screenshot below.

Screenshot of the error:
image

dT=dTCommissionData.DefaultView.ToTable(False,"TERMINAL","TERMINA_LCIF","TERMINAL_NAME","BRANCH","REGION","Number_of_Transactions","TRAN_AMT","AGENT_COMMISSION","INTERSWITCH_COMMISSION").CopyToDataTable

That’s the linq query am trying to use.
Kindly advise on what I can do to resolve it.

Regards,
Kakooza Allan Klaus

@Kakooza-Allan-Klaus

Just remove the CopyToDataTable and the column names should be inside { }

dT=dTCommissionData.DefaultView.ToTable(False,{"TERMINAL","TERMINA_LCIF","TERMINAL_NAME","BRANCH","REGION","Number_of_Transactions","TRAN_AMT","AGENT_COMMISSION","INTERSWITCH_COMMISSION"})

Because, DefaultView.ToTable returns a data table only

The documentation link

1 Like

its not a LINQ related Operatoras it comes from origin DataTable Class definition

CopyToDataTable is not defined by the class DataTable as the message mentioned
the above statement without CopyToDataTable already returns a datatable

When using DataSetExtensions then in some scenarios we can use the extension method e.g. a List(Of DataRow). For making this available then we would take care about the assembly reference.

we hope the case is more clear now

1 Like

@kumar.varun2
After implementing the changes you advised
Now am getting the error of Column ‘TERMINAL’ does not belong to underlying table ‘DataTable’

dT=dTCommissionData.DefaultView.ToTable(False,{“TERMINAL”,“TERMINA_LCIF”,“TERMINAL_NAME”,“BRANCH”,“REGION”,“Number_of_Transactions”,“TRAN_AMT”,“AGENT_COMMISSION”,“INTERSWITCH_COMMISSION”})

Kindly advise on what I can change.
Thanks

Hi @Kakooza-Allan-Klaus

dtCommissionData does not have a column with the name “TERMINAL”.

Check the data table columns in the debug mode by writing the following in the immediate panel.

dtCommissionData.Columns

This will list all the columns in the data table.

1 Like

Yes @kumar.varun2 your right because I deselected the Add Headers option because I was getting the error of already exists in DataTable and the resolution was to uncheck the Add Headers option.

So am wondering on how I can resolve this new error.

Let me try and do what you’ve advised and see

And I was thinking if I can use the index position instead of the column name I guess it will more stable that way.

How can I refractor my code to support that.

Thanks.

1 Like

Thanks @kumar.varun2,

I managed to resolve the issue following your guidelines.

I used the Read and Write Range activities without checking the Add Headers option.
And also used this query:

dT=dTCommissionData.DefaultView.ToTable(False,{“TERMINAL”,“TERMINA_LCIF”,“TERMINAL_NAME”,“BRANCH”,“REGION”,“Number_of_Transactions”,“TRAN_AMT”,“AGENT_COMMISSION”,“INTERSWITCH_COMMISSION”})

Substituting the column names with the column names I got using

dtCommissionData.Columns

In the immediate panel using the Debug mode.

1 Like

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