Convert DataTable to List

后端 未结 14 1804
挽巷
挽巷 2020-12-04 12:09

I have an strongly typed DataTable of type MyType, I\'d like convert it in a List.

How can I do this ?

Thanks.

14条回答
  •  一向
    一向 (楼主)
    2020-12-04 12:46

    Assuming your DataRows inherit from your own type, say MyDataRowType, this should work:

    List list = new List();
    
    foreach(DataRow row in dataTable.Rows)
    {
        list.Add((MyDataRowType)row);
    }
    

    This is assuming, as you said in a comment, that you're using .NET 2.0 and don't have access to the LINQ extension methods.

提交回复
热议问题