dataset to Listusing linq

前端 未结 6 637
别跟我提以往
别跟我提以往 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:08

    First of all, you're on the right track, but you should be thinking in terms of IEnumerable rather than List. And here is how you would do that:

     var myData = ds.Tables[0].AsEnumerable()
                      .Select(r => new {column1 = r[0].ToString(), 
                                        column2 = r[1].ToString() 
                                        /*etc*/
                              });
    

    Never convert an IEnumerable to a List before you absolutely need to.

提交回复
热议问题