I have few methods that returns different Generic Lists.
Exists in .net any class static method or whatever to convert any list into a datatable? The only thing that i can imagine is use Reflection to do this.
IF i have this:
List<Whatever> whatever = new List<Whatever>();
(This next code doesn't work of course, but i would like to have the possibility of:
DataTable dt = (DataTable) whatever;
This is the simple Console Application to convert List to Datatable.
Se probó el método para que acepte campos con null.
This is a simple mix of the solutions. It work with Nullable types.
It's also possible through XmlSerialization. The idea is - serialize to XML and then readXml method of DataSet.
I use this code (from an answer in SO, forgot where)
so then it's as simple as:
Not sure how it stands against all the other answers of this post, but it's also a possibility.
Marc Gravell's answer but in VB.NET
This link on MSDN is worth a visit: How to: Implement CopyToDataTable<T> Where the Generic Type T Is Not a DataRow
This adds an extension method that lets you do this: