troubleshooting Question

How can i pass my list to a DataTable  and Load same to a Grid

Avatar of Olukayode Oluwole
Olukayode OluwoleFlag for Canada asked on
2 Comments1 Solution66 ViewsLast Modified:
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)
            PropertyDescriptorCollection properties =
            DataTable table = new DataTable();
            foreach (PropertyDescriptor prop in properties)
                table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
            foreach (T item in data)
                DataRow row = table.NewRow();
                foreach (PropertyDescriptor prop in properties)
                    row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
            return table;

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


Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros