其实用from..Linq语句做外连接简单而且便于理解,我个人使用lamdba纯粹是技术上的追求吧
DataTable exceldt=new DataTable();
DataTable nomacdt=new DataTable();
exceldt = exceldt.AsEnumerable().GroupJoin(nomacdt.AsEnumerable(), a => a.Field<String>("COP_G_NO"), b => b.Field<String>("newmachineType"), (a, b) => new
{
G_NO = a.Field<Int32>("G_NO"),
COP_G_NO = a.Field<String>("COP_G_NO"),
G_QTY = a.Field<String>("G_QTY"),
QTY_1 = a.Field<String>("QTY_1"),
NET_WT = String.IsNullOrWhiteSpace(a.Field<String>("NET_WT")) ? (nomacdt.Rows.Count > 0 ? b.Select(c => c.Field<Decimal>("NW")).Single().ToString() : a.Field<String>("NET_WT")) : a.Field<String>("NET_WT"),
GROSS_WT = String.IsNullOrWhiteSpace(a.Field<String>("GROSS_WT")) ? (nomacdt.Rows.Count > 0 ? b.Select(c => c.Field<Decimal>("GW")).Single().ToString() : a.Field<String>("GROSS_WT")) : a.Field<String>("GROSS_WT"),
}).ToDataTable();