Best way is use DISTINCT Keyword in Database Query, but some times we may fill the data manually.
We can remove by using two type
First One is very simple and it is used when we need to compare all columns in the rows.
DataTable _NewTable=_Table.DefaultView.ToTable(true);
Second, Suppose we need to remove the rows for specific columns only means then we can go for the following MethodList<string> keyColumns = new List<string>();
keyColumns.Add("Column1");
keyColumns.Add("Column2");
RemoveDuplicatesFromDataTable(ref _Table, keyColumns);
{
Dictionary<string, string> uniquenessDict = new Dictionary<string, string>(table.Rows.Count);
StringBuilder stringBuilder = null;
int rowIndex = 0;
DataRow row;
DataRowCollection rows = table.Rows;
while (rowIndex < rows.Count - 1)
{
row = rows[rowIndex];
stringBuilder = new StringBuilder();
foreach (string colname in keyColumns)
{
stringBuilder.Append(((string)row[colname]));
}
if (uniquenessDict.ContainsKey(stringBuilder.ToString()))
{
rows.Remove(row);
}
else
{
uniquenessDict.Add(stringBuilder.ToString(), string.Empty);
rowIndex++;
}
}
}