DataTable通过dt.AsEnumerable()方法转换可用Linq查询,反之,Linq也可以转化为DataTable
DataTable newDt = query1.CopyToDataTable<DataRow>();
var query1 =
from stu in dtStu.AsEnumerable()
from score in dtScore.AsEnumerable()
where stu.Field<int>("ScoreID") == score.Field<int>("ScoreID")
where (int)stu["Age"] > 20
select stu;
//通过CopyToDataTable()方法创建新的副本
DataTable newDt = query1.CopyToDataTable<DataRow>();
foreach (var item in newDt.AsEnumerable())
{
System.Console.WriteLine(item["Name"]);
}
DataTable与Linq相互转换
最新推荐文章于 2024-07-12 23:08:38 发布