I have a List in my c# application prepared using LINQ
The list is generated and i need to pass it to a ListToDataTable processor in my Library
before loading to a Grid
The List to Datatable Script in my Library is as shown below
[] public static class ListToDataTableProcessor
{
public static DataTable ToDataTable<T>(this IList<T> data)
{
PropertyDescriptorCollecti
on properties =
TypeDescriptor.GetProperti
es(typeof(
T));
DataTable table = new DataTable();
foreach (PropertyDescriptor prop in properties)
table.Columns.Add(prop.Nam
e, Nullable.GetUnderlyingType
(prop.Prop
ertyType) ?? prop.PropertyType);
foreach (T item in data)
{
DataRow row = table.NewRow();
foreach (PropertyDescriptor prop in properties)
row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
table.Rows.Add(row);
}
return table;
}
}[/code]
My application LINQ script that generates the List is shown below with the last 2 lines flagged.
I am trying to pass the list to the Processor and return a DataTable (see screen below)
![List to DataTable Script]()
The list generation is ok. I just do not know how to correct the error reported
and how to pass the list to the processor and get the returned Table
I will be Grateful for any Help
Thank
Olukay
You always made my day with your proof of concept