c# - How to convert a list into data table - Stack Overflow
stackoverflow.com › questions › 18100783you can use this extension method and call it like this. DataTable dt = YourList.ToDataTable (); public static DataTable ToDataTable<T> (this List<T> iList) { DataTable dataTable = new DataTable (); PropertyDescriptorCollection propertyDescriptorCollection = TypeDescriptor.GetProperties (typeof (T)); for (int i = 0; i < propertyDescriptorCollection.Count; i++) { PropertyDescriptor propertyDescriptor = propertyDescriptorCollection [i]; Type type = propertyDescriptor.PropertyType; if ...
c# list to datatable Code Example - IQCode.com
iqcode.com › code › csharpJan 22, 2022 · just add this function and call it, it will convert list to datatable. public static datatable todatatable (list items) { datatable datatable = new datatable (typeof (t).name); //get all the properties propertyinfo [] props = typeof (t).getproperties (bindingflags.public | bindingflags.instance); foreach (propertyinfo prop in props) { …