Convert DataSet to List

后端 未结 11 2201
一整个雨季
一整个雨季 2020-12-04 08:39

Here is my c# code

Employee objEmp = new Employee();
List empList = new List();
foreach (DataRow dr in ds.Tables[0].Rows)
{
          


        
11条回答
  •  执笔经年
    2020-12-04 08:59

    Try something like this:

    var empList = ds.Tables[0].AsEnumerable()
        .Select(dataRow => new Employee
        {
            Name = dataRow.Field("Name")
        }).ToList();
    

提交回复
热议问题