日期:2014-05-17  浏览次数:20467 次

得到datatable中重复的数据并显示
怎么得到datatable中重复的数据并显示,要是用两个for循环,这样会慢很多。有没有其他方法?

------解决方案--------------------
 是要取消某个字段的重复项?然后绑定?
------解决方案--------------------
创建datatable2  你所谓重复是指哪个字段重复 group by 一下 统计出来重复的数据 放到datatable2中
------解决方案--------------------
引用:
在datatable中根据金额,卡号判断,如果有重复的,就把重复的显示,给提示。让重新修改卡号。

Quote: 引用:

 是要取消某个字段的重复项?然后绑定?


根据金额和卡号查询出表中的所有重复的记录?
可以考虑用这个查询语句

select col_1,col_2,count(1) from table  group by col_1,col_2  having count(1) >1;

------解决方案--------------------
是说导入的时候不能导入重复数据么?那就在insert的时候判断一下,用
if not exists (select 1 from table where id =?id)
insert into table .....
else
.....
------解决方案--------------------
可以用linq
select col_1,col_2,count(1) from table  group by col_1,col_2  having count(1) >1;

var query=from d in dt.AsEnumrable()
          group d by new{ d.Field<string>("卡号"), d.Field<decimal>("金额")} into g
             where g.Count() >= 10
    select new
 {
        g.Key,
        。。。
    };