You have a few choices here:
1. Add a Primary Key
you can add a primary key to your data table when creating it.
Assuming you had a column called "Id" then you would do it this way:
AllItems.PrimaryKey = new DataColumn[] { workTable.Columns["Id"] };}
Or, for cases where your primary key is a composite key (multiple columns):
AllItems.PrimaryKey = new DataColumn[] {
workTable.Columns["Id"],
workTable.Columns["Name"] };}
This would then allow Contains to work correctly.
2. Use a DataView
You can use a DataView to filter out the distinct rows;
DataView view = new DataView(AllItems);
DataTable distinctValues = view.ToTable(true, "Column1", "Column2" , ..., "ColumnN");
3. Find Matching Rows using Select
Or you can rely on the Select method to test if a corresponding row exists in the Items
DataTable based on a statement that's like a SQL WHEREclause:
List<DataRow> rowsToRemove = new List<DataRow>();
foreach(DataRow allItemRow in AllItems.Rows)
{
if(Items.Select(String.Format("Id = {0}"),
allItemRow.Field<Int32>("Id")).Length == 0)
{
rowsToRemove.Add(allItemRow);
}
}
rowsToRemove.ForEach(x => x.Delete());
AllItems.AcceptChanges();
Note that it's important NOT to remove rows while you are iterating the collection of Rows in AllItems - instead, collect these rows, and remove them afterwards.
4. Filter on the way in
Also note, and I haven't tried it, but, depending on how you are selecting the rows out of Excel, you may be able to use the SQL DISTINCT clause; if you are using ODBC to load data from Excel then you could try filtering at source.