Diese Methode löscht doppelte Zeilen aus einer DataTable.
/// <summary>
/// Removes duplicate rows in a DataTable.
/// </summary>
/// <param name="dataTable">The DataTable.</param>
/// <param name="columnName">Name of the column</param>
private static void RemoveDuplicateRows(DataTable dataTable, string columnName)
{
Hashtable hashTable = new Hashtable();
List<DataRow> duplicateList = new List<DataRow>();
foreach (DataRow dataRow in dataTable.Rows)
try
{
hashTable.Add(dataRow[columnName], string.Empty);
}
catch
{
duplicateList.Add(dataRow);
}
foreach (DataRow dataRow in duplicateList)
dataTable.Rows.Remove(dataRow);
}
2 Kommentare zum Snippet