Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use System.Data.DataTableExtensions' CopyToDataTable method?
    text
    copied!<p>I'd like to create a data table given a List using the CopyToDataTable method available in DataTableExtensions. I've previously asked the question <a href="https://stackoverflow.com/questions/523153/how-do-i-transform-a-listt-into-a-dataset">How do I transform a List into a DataSet?</a> and got an <a href="https://stackoverflow.com/questions/523153/how-do-i-transform-a-listt-into-a-dataset/523168#523168">exceptional answer</a> from <a href="https://stackoverflow.com/users/5445/cms">CMS</a> which was to achieve what I wanted by creating an extension <code>public static DataTable ToDataTable&lt;T&gt;(this IEnumerable&lt;T&gt; collection)</code></p> <p>I've been using what he suggested...but recently I've <a href="http://www.danielmoth.com/Blog/2007/07/linq-to-dataset.html" rel="nofollow noreferrer">seen in a blog</a> that there already exists such an extension... <code>CopyToDataTable&lt;T&gt;(this IEnumerable&lt;T&gt; source) : DataTable</code> which exists in System.Data.DataTableExtensions.</p> <p>As a result, I figure I should switch over to using this inbuilt extension method instead of using one that I'd have to maintain myself.</p> <p>Unfortunately, I'm having a bit of trouble figuring out how to use it.</p> <p>I can take my IList and say myListofMyClass.CopyToDataTable() but I get a compile error that says "The type 'MyClass' must be convertible to 'System.Data.DataRow' in order to use it as parameter 'T' in the generic method..."</p> <p>Is there something special I need to do MyClass in order to make it convertible to System.Data.DataRow? Is there some interface I need to implement?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload