The statement
dt.AsEnumerable().Take(15)
given in the question retrieves the first 15 records and returns an
IEnumerable
of
DataRow
as explained here
http://msdn.microsoft.com/en-us/library/bb503062.aspx[
^]
The issue is not because of
Take(15)
, but because of
CopyToDataTable
method.
CopyToDataTable
has
three over loads
as explained here
http://msdn.microsoft.com/en-us/library/bb360272[
^]
The first overload does not take any parameter and returns a
DataTable
.
Whereas the
Second
and
Third
overloads take a
DataTable
as an argument and copy the rows returned by the query in to this
DataTable
. While doing so the
LoadOption
parameter is also must in both the overloads.
So there is no over load of
CopyToDataTable
method which takes only 1 argument. Hence, the error is thrown.
The
LoadOption
parameter gives the options explained here
http://msdn.microsoft.com/en-us/library/system.data.loadoption[
^]
So for the query to execute and give the top 15 records either call it as
var dtnew = dt.AsEnumerable().Take(15).CopyToDataTable();
or as
dt.AsEnumerable().Take(15).CopyToDataTable(dtnew,LoadOption.OverwriteChanges);