DataTable判断是否存在相同的值,存在的话直接抛异常:
DataTable dt = new DataTable();
var InputList = dt.AsEnumerable().Select(
p => new
{
SourcePlatformCode = p["SourcePlatformCode"].ToString().Trim(),
SourcePlatformName = p["SourcePlatformName"].ToString().Trim(),
}).ToList();
var douList = InputList.GroupBy(p => new { p.SourcePlatformCode, p.SourcePlatformName }).Select(g => new { device = g.Key, cnt = g.Count() }).ToList();
if (douList.Find(p => p.cnt > 1) != null)
{
throw new Exception("请检查是否有重复数据!");
}