How to transform DataRow to DataTable

DataRow is a .Net structure - check MSDN:

I am having a and Array of DataRows but copytoDataTable function is not available.

I tried clone method to create new data table and add individual row, but getting “This row already belongs to another table”.

Hey @ezharul.ansari

CopyToDataTable() only works when your query returns an IEnumerable<System.Data.DataRow>

Like this:

IEnumerable<System.Data.DataRow> new_dt = dataTable.AsEnumerable().CopyToDataTable()


An Array<T> is an IEnumerable<T>, since all arrays (and most other collections available in system.collections and system.collections.generic) implement the IEnumerable (or IEnumerable<T>) interface. You don’t need to cast a class that implements an interface to call a method inherited from that interface.
So a DataRow[] is an IEnumerable<DataRow> by default.

Did you try just typing it in?
Sometimes intellisense (autocompletion) doesn’t kick in the first time, but the workflow should work correctly.

1 Like

Yes u r correct. I just was aware some day back with this fact when i was just Reading about it and intellisense will not give error with this too but really strange that day it was returning error so i was not able to execute but now its works.

It works:+1: Intellisense :frowning:

The CopyToDataTable, as well as a couple of other useful ones (like .AsEnumerable()) are in a separate .dll.
There were some issues in the past that this .dll didn’t load correctly until it was referenced, you might’ve stumbled upon that just now.

Yeah seems like that that is bcz when it does not work for me in past i started always to prefer Ienumerable data row collection.
So such probs can exists with others utility functions as well? @andrzej.kniola?

I’m only aware of this happening with System.Data.DataSetExtensions.dll.
Affected methods are here on MSDN:

Basically it’s .AsEnumerable(), .CopyToDataTable() and .AsDataView() (and their overloads).


I have faced some in the past but solved by referencing but

Returns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.


1 Like

This issue is still live and easy to reproduce, at least for me. I have the same thing, with this namespace and also with DataRowExtensions; in fact they do not automatically get imported or even pop up when I start typing System.Data into the Imports field.

Interestingly enough all the functions do work; the validation warning icon will disappear once you have the syntax correct, you just have to manage without the nice intellisense prompt.

Just as a sidenote - System.Data.DataSetExtensions is the library file name. Methods that it contains actually are in System.Data namespace (which is already present by default), so there’s nothing to add from Imports panel as it’s already there.
This is what might actually be confusing the Studio, as it’s not adding a namespace, it’s extending it.

Indeed, that’s why I suggested just typing it in. For me Intellisense catches on after using it and restarting the Studio - seems it doesn’t support hot-reload.
If it would not be working at all, you can also check directly in the xaml for assembly reference to that dll (and add it manually if needed).


Good point, I forgot about this and I think you’re right. This must be the crucial difference between these extensions and others, like those in System.Linq, that work just fine out of the box.

I was facing the same problem as described above.
But “.ItemArray” did the trick.

Hi folks,

i have a problem adding rows to a datatable, this is my flow:

and this is the error that returns:


please could you tell me what i doing wrong?

thanks to all!!.

Invoke ImportRow should solve this


Hi tdhaene,

thanks!! , do you mean inside for each row? or is elsewhere. (15.1 KB)

thanks!!, BR

Inside For each row

1 Like

Hi tdhaene,

first thanks for your advices, i tried to put invoke method but get a new error:


thanks!! BR.

Did you add in parameters: type datarow, value row


Hi folks,

thanks thhaene!! works great!!

:wink: :wink:

thanks!! BR.