最好的方法从数据表中删除重复项 [英] Best way to remove duplicate entries from a data table
本文介绍了最好的方法从数据表中删除重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是从数据表中删除重复项的最佳方式是什么?
What is the best way to remove duplicate entries from a Data Table?
推荐答案
删除重复
public DataTable RemoveDuplicateRows(DataTable dTable, string colName)
{
Hashtable hTable = new Hashtable();
ArrayList duplicateList = new ArrayList();
//Add list of all the unique item value to hashtable, which stores combination of key, value pair.
//And add duplicate item value in arraylist.
foreach (DataRow drow in dTable.Rows)
{
if (hTable.Contains(drow[colName]))
duplicateList.Add(drow);
else
hTable.Add(drow[colName], string.Empty);
}
//Removing a list of duplicate items from datatable.
foreach (DataRow dRow in duplicateList)
dTable.Rows.Remove(dRow);
//Datatable which contains unique records will be return as output.
return dTable;
}
下面以下链接
<一个href="http://www.dotnetspider.com/resources/4535-Remove-duplicate-records-from-table.aspx">http://www.dotnetspider.com/resources/4535-Remove-duplicate-records-from-table.aspx
<一个href="http://www.dotnetspark.com/kb/94-remove-duplicate-rows-value-from-datatable.aspx">http://www.dotnetspark.com/kb/94-remove-duplicate-rows-value-from-datatable.aspx
有关删除列重复
<一个href="http://dotnetguts.blogspot.com/2007/02/removing-duplicate-records-from.html">http://dotnetguts.blogspot.com/2007/02/removing-duplicate-records-from.html
这篇关于最好的方法从数据表中删除重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文