dataset to Listusing linq

前端 未结 6 639
别跟我提以往
别跟我提以往 2021-02-06 13:18

I have a DataSet and I want to convert the DataSet into List

T - type object

How convert my DataSet?

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-06 14:12

    This is pretty much the same as the other answers, but introduces strongly-typed columns.

    var myData = ds.Tables[0].AsEnumerable().Select(r => new {
        column1 = r.Field("column1"),
        column2 = r.Field("column2"), 
        column3 = r.Field("column3")
    });
    var list = myData.ToList(); // For if you really need a List and not IEnumerable
    

提交回复
热议问题