合并:

DataTable pros=xxx;

DataTable pstar=yyy;

//将两张DataTable合成一张

foreach (DataRow dr in pstar.Rows)

{

pros.ImportRow(dr);

}

DataTable设置主键,并判断重复

DataTable allpros =xxx;

单列设为主键:

//设置第某列为主键

allpros.PrimaryKey = new DataColumn[] { pros.Columns[0]};

foreach (DataRow dr in pros.Rows)

{

//排除相同id,相同类型的程序

if (!allpros.Rows.Contains(dr[0]}))

allpros.ImportRow(dr);

}

多列设为主键

allpros.PrimaryKey = new DataColumn[] { pros.Columns[0], pros.Columns[1] };

if (!allpros.Rows.Contains(new object[2]{dr[0],dr[1]}))

allpros.ImportRow(dr);

2016.8.11 DataTable合并及排除重复方法的更多相关文章

  1. ASP.Net【如何合并DataTable,并且去重复方法】

    虽然DataTable.Merge可以很好的实现,但以下代码写出来更好理解 DataTable DataTable1 = new DataTable(); DataTable DataTable2 = ...

  2. 取两个DataTable的交集,删除重复数据

    /// <summary> /// 取两个DataTable的交集,删除重复数据 /// </summary> /// <param name="sourceD ...

  3. 2016年11月30日 星期三 --出埃及记 Exodus 20:21

    2016年11月30日 星期三 --出埃及记 Exodus 20:21 The people remained at a distance, while Moses approached the th ...

  4. 2016年11月29日 星期二 --出埃及记 Exodus 20:20

    2016年11月29日 星期二 --出埃及记 Exodus 20:20 Moses said to the people, "Do not be afraid. God has come t ...

  5. 2016年11月28日 星期一 --出埃及记 Exodus 20:19

    2016年11月28日 星期一 --出埃及记 Exodus 20:19 and said to Moses, "Speak to us yourself and we will listen ...

  6. 2016年11月27日 星期日 --出埃及记 Exodus 20:18

    2016年11月27日 星期日 --出埃及记 Exodus 20:18 When the people saw the thunder and lightning and heard the trum ...

  7. 2016年11月26日 星期六 --出埃及记 Exodus 20:17

    2016年11月26日 星期六 --出埃及记 Exodus 20:17 "You shall not covet your neighbor's house. You shall not c ...

  8. 2016年11月25日 星期五 --出埃及记 Exodus 20:16

    2016年11月25日 星期五 --出埃及记 Exodus 20:16 "You shall not give false testimony against your neighbor.不 ...

  9. 2016年11月24日 星期四 --出埃及记 Exodus 20:15

    2016年11月24日 星期四 --出埃及记 Exodus 20:15 "You shall not steal.不可偷盗.

随机推荐

  1. 关于UML方法学图中类之间的关系:依赖,泛化,关联

    类与类图 1) 类(Class)封装了数据和行为,是面向对象的重要组成部分,它是具有相同属性.操作.关系的对象集合的总称. 2) 在系统中,每个类具有一定的职责,职责指的是类所担任的任务,即类要完成什 ...

  2. MySQL随机取数据

    // 随机取9个 $rand_sql = "SELECT * FROM `tf_product` WHERE (`id` >= ((SELECT MAX(`id`) FROM `tf_ ...

  3. JQuery调用iframe子页面函数/对象的方法例子

    父页面有个ID为mainfrm.name为Iframe1的iframe,iframe连接b.html,该页面有个函数test 在父页面调用b.html的test方法为: $("#mainfr ...

  4. tensorflow1.0中的改善

    TensorFlow 1.0 重大功能及改善 XLA(实验版):初始版本的XLA,针对TensorFlow图(graph)的专用编译器,面向CPU和GPU. TensorFlow Debugger(t ...

  5. 智课雅思词汇---十六、前缀hyper和hypo是反义词

    智课雅思词汇---十六.前缀hyper和hypo是反义词 一.总结 一句话总结: hypertension 过度紧张:高血压(hyper+tension紧张) hypotension 低血压 1.ep ...

  6. dp1--乘积最大

    dp1--乘积最大 一.心得 1.用excel填数组很方便 2. dp就是填表 找状态就是缩小规模 找状态转移方程就是 找状态的最后一次关系 二.题目 8782:乘积最大 查看 提交 统计 提问 总时 ...

  7. ubuntu更改启动顺序

    在ubuntu中修改启动配置. 启动相关grub2主要包含下面三个文件:1.   /boot/grub/grub.cfg 文件    2.   /etc/grub.d/ 文件夹   3.   /etc ...

  8. Xcode Developer Tools

    打开Xcode,执行菜单命令 Xcode - Open Developer Tool - More Developer Tools... 会打开苹果开发者中心的工具下载页面. 这里包含了xcode未安 ...

  9. 修复 Xcode 错误 “The identity used to sign the executable is no longer valid”

    如图: 解决方法来自:http://stackoverflow.com/questions/7088441/the-identity-used-to-sign-the-executable-is-no ...

  10. Android中播放DSD音乐

    Github上有个简单的Alsa DSD测试程序,可以播放DSD,地址位于:https://github.com/zonque/alsa-dsd-player 细看其代码,发现有ALSA_FORMAT ...