Skip to main content

DataTable: Finding Differences in Column Values

·64 words·1 min
Darren Pruitt
Author
Darren Pruitt

I have two tables in a typed DataSet and I want to compare one column in each table to see if TableA has values that are not in TableB.

IEnumerable<string> valuesInA =
      typedDataSet.TableA.AsEnumerable().Select(row => row.AField);

IEnumerable<string> valuesInB = typedDataSet.TableB.AsEnumerable().Select(row
      => row.BField);
foreach (var notInB in valuesInA.Except(valuesInB))

    Debug.WriteLine(string.Format("Value not in TableB.BField: {0}", notInB));

This is assuming that both AField and BField are the same type.