如何从linq或edmx查询获取数据到Datatable [英] How to get Data from linq or edmx query to Datatable
本文介绍了如何从linq或edmx查询获取数据到Datatable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
如何使用c#.net从linq查询获取数据到datable,可以指导我或发送snippets
Hi All,
how to get data from linq query to datable using c#.net , can u guide me or send snippets
推荐答案
DataTable workTable = new DataTable();
workTable.Columns.Add("ContryID", typeof(Int32));
workTable.Columns.Add("CountryName", typeof(string));
Data.TestEntities ent = new Data.TestEntities();
var country = ent.Countries.ToList();
foreach (var item in country)
{
DataRow workRow = workTable.NewRow();
workRow["ContryID"] = item.CountryID;
workRow["CountryName"] = item.CountryName;
workTable.Rows.Add(workRow);
}
现在你可以用你的workTable进行anuthing
快乐编码:) :) :)
now you can do anuthing with your workTable
happy coding :) :) :)
我认为不需要从.edmx获取数据到数据表,列表/通用列表重量轻,你应该使用相同的。
但是如果你想要
你可以通过foreach将数据从列表复制到数据表,如上面的答案。
问候,
Manoj
I think no need to get data from .edmx to data table, List/Generic list is light weight and you should use the same.
But if you want
you can copy data from list to Data-Table by foreach as in above answer.
Regards,
Manoj
这篇关于如何从linq或edmx查询获取数据到Datatable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文