去除DataTable中的重复行
来源:互联网 发布:淘宝买片该搜什么 编辑:程序博客网 时间:2024/04/28 20:01
#region 过滤DataTable中的指定字段重复的行
/// <summary>
/// 过滤DataTable中的指定字段重复的行
/// </summary>
/// <param name= "dt "> </param>
/// <param name= "FieldName "> </param>
/// <returns> </returns>
public DataTable SelectDistinctByField(DataTable dt, string FieldName)
{
DataTable returnDt = new DataTable();
returnDt = dt.Copy();//将原DataTable复制一个新的
DataRow[] drs = returnDt.Select( " ", FieldName);//将DataTable按指定的字段排序
object LastValue = null;
for(int i = 0; i < drs.Length; i++)
{
if((LastValue == null) || (!(ColumnEqual(LastValue, drs[i][FieldName]))))
{
LastValue = drs[i][FieldName];
continue;
}
drs[i].Delete();
}
return returnDt;
}
private bool ColumnEqual(object A, object B)
{
// Compares two values to see if they are equal. Also compares DBNULL.Value.
// Note: If your DataTable contains object fields, then you must extend this
// function to handle them in a meaningful way if you intend to group on them.
if ( A == DBNull.Value && B == DBNull.Value ) // both are DBNull.Value
return true;
if ( A == DBNull.Value || B == DBNull.Value ) // only one is DBNull.Value
return false;
return ( A.Equals(B) ); // value type standard comparison
}
#endregion
- 去除DataTable中的重复行
- 去除DataTable中的重复行
- DataTable如何去除重复的行
- DataTable去除重复数据
- 根据某列的值去除DataTable中重复行
- C# 中怎样去除DataTable表里面的重复行
- Ajax实现的明细去除重复 datatable去除重复
- 快速找出DataTable中的重复行
- 每日学习总结:DataTable中去除重复的项、SQL中的各种Join连接讲解
- 怎样去除EXCEL中的重复行
- Java去除文件中的重复行
- 怎样去除EXCEL中的重复行
- 怎样去除EXCEL中的重复行
- 去掉DataTable重复行
- DataTable去掉重复行
- datatable重复行合并
- 过滤DataTable中的指定字段重复的行
- 过滤DataTable中的指定字段重复的行
- 如何增量 Visual c + + 中的每个版本后的版本信息
- PHP连接mssql的配置
- Windows netstat 查看端口 进程占用
- Android开发中AsyncTask实现异步处理任务的方法
- 多线程内数据长效保护的问题
- 去除DataTable中的重复行
- Python3.x和Python2.x的区别
- 平台2.3升级到2.4的问题
- 浅析ORACLE ERP系统维护方法
- 网页DIV接收键盘按键消息解决办法
- 奔驰(javascript)(用谷歌浏览器解析比较快)
- sicily 1014 Specialized Four-Dig
- HtmlElement 基础知识
- Spring 中 commons-logging 包