C# 查看datatable 是否里面是否包含同时相等的几个字段
//dtData是datatable var InputList = dtData.AsEnumerable().Select( p => new { Device = p["DEVICE"].ToString().Trim(), Operation = p["OPERATION"].ToString().Trim(), MATERIALTYPE = p["MATERIALTYPE"].ToString().Trim(), Status = p["Status"].ToString().Trim(), DescrIption = p["Description"].ToString().Trim(), MaterialSEQ = p["MaterialSEQ"].ToString().Trim(), }).ToList(); var douList = InputList.GroupBy(p => new { p.Device, p.Operation,p.MATERIALTYPE }).Select(g => new { device = g.Key, cnt = g.Count() }).ToList(); if (douList.Find(p => p.cnt > 1) != null) { throw new CimesException(AOIMessage.Error.T00710("DEVICEGROUP,OPERATION,MATERIALTYPE")); }
上述代码的意思,就是查看dtData里面是否有一行,Device,Operation,MATERIALTYPE 同时相同,如果同时相同,则报错
dtData里面的内容
InputList里面的内容