日期:2014-05-20 浏览次数:20991 次
DataTable dt_A = new DataTable();
dt_A.Columns.Add("Name", typeof(string));
dt_A.Columns.Add("Age", typeof(int));
DataTable dt_B = new DataTable();
dt_B.Columns.Add("Name", typeof(string));
dt_B.Columns.Add("Age", typeof(int));
dt_A.Rows.Add("Kitty", 12);
dt_A.Rows.Add("Tom", 24);
dt_A.Rows.Add("Kelly", 22);
dt_B.Rows.Add("Kitty", 12);
dt_B.Rows.Add("Tom", 27);
dt_B.Rows.Add("Jhon", 22);
var singleQuery = dt_A.AsEnumerable().Where(stu => stu.Field<int>("Age") > 20).Select(stu => stu);
stu => stu.Field<int>("Age") > 20
var doubleQuery = from a in dt_A.AsEnumerable()
from b in dt_B.AsEnumerable()
where a.Field<string>("Name") == b.Field<string>("Name") &&
a.Field<int>("Age") != b.Field<int>("Age")
select new
{
Name = a.Field<string>("Name"),
A_Age = a.Field<int>("Age"),
B_Age = b.Field<int>("Age")