日期:2014-05-20 浏览次数:20984 次
void Main() { DataTable dt1 = new DataTable(); dt1.Columns.Add("c1"); dt1.Columns.Add("c2"); DataRow dr1 = dt1.NewRow(); dr1["c1"] = "a"; dr1["c2"] = "ad"; dt1.Rows.Add(dr1); DataTable dt2 = new DataTable(); dt2.Columns.Add("c3"); dt2.Columns.Add("c4"); DataRow dr2 = dt2.NewRow(); dr2["c3"] = "a"; dr2["c4"] = "b"; DataRow dr3 = dt2.NewRow(); dr3["c3"] = "a"; dr3["c4"] = "c"; dt2.Rows.Add(dr2); dt2.Rows.Add(dr3); var query=from t1 in dt1.AsEnumerable() join t2 in dt2.AsEnumerable() on t1.Field<string>("c1") equals t2.Field<string>("c3") select new { c1=t1.Field<string>("c1"), c2=t1.Field<string>("c2"), c4=t2.Field<string>("c4") }; }