Convert a DataTable to a List<> using C#
Feb 10, 2010
Question is...
To convert a DataTable to a List<> in .NET 2.0.
Here’s the code to do so:
Please note that this is just a prototype and may not cover all scenarios.
Note: I have not tested this but in .NET 3.5, you should be able to do this:
Convert a DataTable to a List<> using C#
To convert a DataTable to a List<> in .NET 2.0.
Here’s the code to do so:
// Assuming there is a DataTable called dt
List<DataRow> drlist = new List<DataRow>();
foreach (DataRow row in dt.Rows)
{
drlist.Add((DataRow)row);
}
Please note that this is just a prototype and may not cover all scenarios.
Note: I have not tested this but in .NET 3.5, you should be able to do this:
List<DataRow> drlist = dt.AsEnumerable().ToList();
Share