由网友(关山渡)分享简介:什么是从数据表中删除重复项的最佳方式是什么?What is the best way to remove duplicate entries from a Data Table?推荐答案删除重复public DataTable RemoveDuplicateRows(DataTable dTable, stri...
什么是从数据表中删除重复项的最佳方式是什么?
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;
}
下面以下链接
http://www.dotnetspider.com/resources/4535-Remove-duplicate-records-from-table.aspx
http://www.dotnetspark.com/kb/94-remove-duplicate-rows-value-from-datatable.aspx
有关删除列重复
http://dotnetguts.blogspot.com/2007/02/removing-duplicate-records-from.html
相关推荐
最新文章