C# convert list to datatable (inner list and dictionery also)

Jul 14 2012 6:17 AM

I need to create DataTable() from my List class. My DataTable should contain all the values of List or Dictionery which is in List class.I want the rows to be duplicated with all values of Dictionery or List values.

I want all the other properties to be duplicated with respect to List.. i.e Non System.Collections.Generic properties should be duplicated based on the lenght of the System.Collections.Generic properties.

For Ex:

Employee object has name, age,List, Dictionery

say,

name = "mike" 
 
age
= "30" 
 
List<string> certificateGot = new List<String> 
 
CertificateGot.Add("MSCE"); 
 
CertificateGot.Add("MCP"); 

Now add CertificateGot to List object..

Dictionery<string,string> prevCompNameandPlace = new Dictionery<string, string>(); 
 
prevCompNameandPlace
.Add("xyz", "London") 
prevCompNameandPlace
.Add("abc", "USA") 

Now add prevCompNameandPlace to List object..

In my datatable I need like this

       Name    Age    CertificateGot NamePlace 
 
       
Mike     30      MSCE          -- 
       
Mike     30      MCP           -- 
       
Mike     30      --           xyz,London 
       
Mike     30      --           abc,USA 

I want all the other properties to be duplicated with respect to List.. i.e Non System.Collections.Generic properties should be duplicated based on the lenght of the System.Collections.Generic properties.

Any help would be appreciated.

Regards, T.N.Nagasundar


Answers (1)