查找datatable 中的重复记录(只查询一个字段)

                StringBuilder str = new StringBuilder();
                var res = new ResParameter() { code = ResponseCode.exception };


                var result = from isbn in dt.AsEnumerable()
                             group isbn by isbn.Field<string>("isbn") into grp
                             where grp.Count() > 1
                             select grp.Key;


                if (result.Count() > 0)
                {
                    foreach (var item in result)
                    {
                        str.Append(item + ",  ");
                    }
                    res.info ="导入EXCEL中包含重复ISBN'  "+ str.ToString()+"'  请整理后再重新导入";
                    return res;
                }

猜你喜欢

转载自www.cnblogs.com/xielideboke/p/10488703.html