/// <summary>
/// Remove duplicate records from data table
/// </summary>
/// <param name="table">DataTable for removing duplicate records</param>
/// <param name="DistinctColumn">Column to check for duplicate values or records</param>
/// <returns></returns>
public
DataTable RemoveDuplicateRows(DataTable table,
string
DistinctColumn)
{
try
{
ArrayList UniqueRecords =
new
ArrayList();
ArrayList DuplicateRecords =
new
ArrayList();
foreach
(DataRow dRow
in
table.Rows)
{
if
(UniqueRecords.Contains(dRow[DistinctColumn]))
DuplicateRecords.Add(dRow);
else
UniqueRecords.Add(dRow[DistinctColumn]);
}
foreach
(DataRow dRow
in
DuplicateRecords)
{
table.Rows.Remove(dRow);
}
return
table;
}
catch
(Exception ex)
{
return
null
;
}
}
No comments:
Post a Comment