转换数据集到列表 [英] Convert DataSet to List
本文介绍了转换数据集到列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的C#code
Here is my c# code
Employee objEmp = new Employee();
List<Employee> empList = new List<Employee>();
foreach (DataRow dr in ds.Tables[0].Rows)
{
empList.Add(new Employee { Name = Convert.ToString(dr["Name"]), Age = Convert.ToInt32(dr["Age"]) });
}
它使用一个循环来创建一个从dataset.Is有什么直接的方法或较短的方法或一行code列表转换数据集列表
It uses a loop to create a List from a dataset.Is there any direct method or shorter method or one line code to convert dataset to list
推荐答案
尝试是这样的:
var empList = ds.Tables[0].AsEnumerable().Select(dataRow => new Employee{Name = dataRow.Field<string>("Name")}).ToList();
这篇关于转换数据集到列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文