Please look at the following:
DataTable newTable = new DataTable();
DataColumn colRMID = new DataColumn();
colRMID.DataType = typeof(System.Int32);
colRMID.ColumnName = "RMID";
DataColumn colCpty = new DataColumn();
colCpty.DataType = typeof(System.String);
colCpty.ColumnName = "Cpty";
newTable.Columns.Add(colRMID);
newTable.Columns.Add(colCpty);
DataRow r1 = newTable.NewRow();
r1["RMID"] = 1234;
r1["Cpty"] = "Internal";
newTable.Rows.Add(r1);
DataRow r2 = newTable.NewRow();
r2["RMID"] = 5678;
r2["Cpty"] = "Wales Fargo";
newTable.Rows.Add(r2);
DataRow r3 = newTable.NewRow();
r3["RMID"] = 1234;
r3["Cpty"] = "External";
newTable.Rows.Add(r3);
DataRow r4 = newTable.NewRow();
r4["RMID"] = 9876;
r4["Cpty"] = "Internal";
newTable.Rows.Add(r4);
I would like to remove all the duplicate rows (having same “RMID”) where “Cpty” = “Internal”.
So that my final output in a datatable should be:
RMID Cpty
5678 "Wales fargo"
1234 "External"
9876 "Internal"
I need to use LINQ
Thanks,
Abhinav
This is not entirely efficient but it is verbose and demonstrates the concept. It also yields the result that you want. I’m sure you can clean it up to better suit your needs.