How do you convert a DataTable into a generic list?

前端 未结 27 2999
后悔当初
后悔当初 2020-11-22 17:04

Currently, I\'m using:

DataTable dt = CreateDataTableInSomeWay();

List list = new List(); 
foreach (DataRow dr in dt.Rows)
{
          


        
27条回答
  •  清歌不尽
    2020-11-22 17:45

    DataTable.Select() doesnt give the Rows in the order they were present in the datatable.

    If order is important I feel iterating over the datarow collection and forming a List is the right way to go or you could also use overload of DataTable.Select(string filterexpression, string sort).

    But this overload may not handle all the ordering (like order by case ...) that SQL provides.

提交回复
热议问题