合并:

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. Hadoop心跳机制源码分析

    正文: 一.体系背景 首先和大家说明一下:hadoop的心跳机制的底层是通过RPC机制实现的,这篇文章我只介绍心跳实现的代码,对于底层的具体实现,大家可以参考我的另几篇博客: 1. hadoop的RP ...

  2. hdu 1695 GCD 莫比乌斯

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  3. UVA 11029 || Lightoj 1282 Leading and Trailing 数学

    Leading and Trailing You are given two integers: n and k, your task is to find the most significant ...

  4. Guest CPU model configuration in libvirt with QEMU/KVM

    每个hypervisor对于guest能看到的cpu model定义都不同,Xen 提供host pass through,所以guest能看到的cpu和host完全相同. QEMU/KVM中gues ...

  5. decimal与 float的区别

      decimal 数据类型最多可存储 38 个数字,所有数字都能够放到小数点的右边.decimal 数据类型存储了一个准确(精确)的数字表达法:不存储值的近似值. 定义 decimal 的列.变量和 ...

  6. jsp:jstl标签库国际化 fmt

    首先资源文件目录是:src/man/sources (这是它默认的资源文件) i18n_en_US.properties文件内容 copyright=Copyright \u00A9 2013 lan ...

  7. ng-file-upload - samples

    <script src="angular.min.js"></script> <!-- shim is needed to support non-H ...

  8. python 百题计划

    一.基础篇 想要像类似执行shell脚本一样执行Python脚本,需要在py文件开头加上什么?KEY:#!/usr/bin/env python Python解释器在加载 .py 文件中的代码时,会对 ...

  9. signal 信号具体含义解释~

    ) SIGHUP 本信号在用户终端连接(正常或非正常)结束时发出,通常是在终端的控 制进程结束时, 通知同一session内的各个作业,这时它们与控制终端不再关联. ) SIGINT 程序终止(int ...

  10. 加密算法之BLOWFISH算法

    加密信息 BlowFish算法用来加密64Bit长度的字符串. BlowFish算法使用两个"盒"--ungignedlongpbox[18]和unsignedlongsbox[4 ...