c# DataTable join 两表连接
转:https://www.cnblogs.com/xuxiaona/p/4000344.html
JlrInfodt和dtsource是两个datatable,通过[姓名]和[lqry]进行关联
var query1 = from rJlrInfodt in JlrInfodt.AsEnumerable() from rdtsource in dtsource.AsEnumerable() where rJlrInfodt.Field<String>("姓名") == rdtsource.Field<String>("lqry") select new { 领取人员 = rdtsource.Field<String>("lqry"), 提交总量 = rdtsource.Field<Int64>("提交总量"), 号 = rJlrInfodt.Field<Double>("号"), 单位 = rJlrInfodt.Field<String>("单位"), }; DataTable DtAll = new DataTable(); DtAll.Columns.Add("领取人员", typeof(String)); DtAll.Columns.Add("提交总量", typeof(Int64)); DtAll.Columns.Add("号", typeof(Double)); DtAll.Columns.Add("单位", typeof(String)); DataTable dtNew = DtAll.Copy(); foreach (var obj in query1) dtNew.Rows.Add(obj.领取人员, obj.提交总量, obj.号, obj.单位);