请问,我现在有两个结构一样的datatable,我想按照主键把不一样的row去掉,如何操作?

解决方案 »

  1.   

    delete tb1 where not exists(select * from tb2 where tb2.key = tb1.key)
      

  2.   

    樓主的意思是在DataTable對象的實例中進行操作?
      

  3.   

    问题是:我现在的datatable是内存的表,不能执行sql操作,谢谢帮忙。
      

  4.   

    对阿,是对datatable对象进行操作。
      

  5.   

    --例子--create table tb1(id int,c int)
    insert tb1
    select 1,1
    union select 2,1
    union select 3,1create table tb2(id int,c int)
    insert tb2
    select 1,1
    union select 5,1
    union select 6,1--先删除tb1中不在tb2中的记录
    delete a
    from tb1 a left join tb2 b on a.id = b.id
    where b.id is null--再先删除tb2中不在tb1中的记录
    delete a
    from tb2 a left join tb1 b on a.id = b.id
    where b.id is nullselect * from tb1
    select * from tb2
    drop table tb1,tb2
      

  6.   

    你不會在後台先把數據取好了,再放到datatable 中
      

  7.   

    這些操作在DataTable中好象是不太好完成,還是放到數據庫去處理吧,畢竟DataTable只是內存表,操作起來不那麼方便的,唯一能想到的方法祇有遍例了...