Click here to Skip to main content
15,743,541 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to covert a DataTable into a List?
I Can do it by looping through the table and populating a list in iterations.

But Is there any other predefined methods are there to achieve this task?
Posted

Did you do a search first:
http://stackoverflow.com/questions/208532/how-do-you-convert-a-datatable-into-a-generic-list[^]

Quote:
If you're using .NET 3.5, you can use DataTableExtensions.AsEnumerable (an extension method) and then if you really need a List<datarow> instead of just IEnumerable<datarow> you can call Enumerable.ToList:

IEnumerable<datarow> sequence = dt.AsEnumerable();

or

List<datarow> list = dt.AsEnumerable().ToList();

First result from Google [^]:)
 
Share this answer
 
v2
Comments
[no name] 12-Sep-12 10:36am    
Dang I answered the same thing. Deleted mine.
Kenneth Haugland 12-Sep-12 10:44am    
Great minds think alike or Google search for the answer :-D
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900