Studio - Error during Add Data Row

I’ve an Excel file with 10 columns and 43 row. The Excel has headers. I read this Excel into a DataTable called (MyDT). Then I initialize a new DataTable using Assign. newDT=new System.Data.Datatable. I use the For Each Row to read the MyDT table. I have a If with Condition row(“Address”).ToString.Contains(“Avenue”) then, if the match happen, I want to add entire row in the newDT. I’m using Add Data Row. It’s giving an error ‘Input array is longer than the number of columns in the table’.
I guess the error is because I have only one row in the newDT datatable.
I want to avoid using Build Data Table. That’s why I initialized it. Can you please tell me how to get rid of this error in the current logic ? Thanks.

1 Like

@Prinal_C Does this newDT supposed to have the same columns as that of the MyDT ?

If so, instead of initialising the newDT, you can clone the MyDT and assign it to the newDT in the below way :

newDT = MyDT.Clone

I believe then the problem should be solved, If not please explain what errors do you get and what changes have you done.

1 Like

Thank you! Yes, the newDT should have the same columns as that of the MyDT. I’ll try this.

1 Like

It worked. Thank you !

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