C# convert List to DataTable (nested list or dictionery also)

Posted by Nagasundar_Tn under C# on 7/14/2012 | Points: 10 | Views : 9722 | Status : [Member] | Replies : 3
Hi Experts,

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

I want all the other properties to be duplicated with respect to List<String>.. 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<string>, Dictionery<string,string>

say,

name = "mike"

age = "30"

List<string> certificateGot = new List<String>

CertificateGot.Add("MSCE");

CertificateGot.Add("MCP");


Now add CertificateGot to List<Employee> object..

Dictionery<string,string> prevCompNameandPlace = new Dictionery<string, string>();

prevCompNameandPlace.Add("xyz", "London")
prevCompNameandPlace.Add("abc", "USA")


Now add prevCompNameandPlace to List<Employee> 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<String>.. 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

Regards,
T.N.Nagasundar



Responses

Posted by: Calvert on: 7/16/2012 [Member] Starter | Points: 25

Up
0
Down
Try hierarchical Win Forms.It control single or multiple headers. It can display data of various types from various sources.
http://www.dapfor.com/en/net-suite/net-grid/tutorial/data-sorting


Nagasundar_Tn, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nagasundar_Tn on: 7/20/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks for your reply.

Regards,
T.N.Nagasundar

Nagasundar_Tn, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Megan00 on: 7/22/2012 [Member] Starter | Points: 25

Up
0
Down
try below link:
http://stackoverflow.com/questions/6344939/how-to-convert-listliststring-to-a-datatable

Never give up! Smile to the world!
http://excelcsharp.blog.com/

Nagasundar_Tn, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response