7

I have two data tables as follows

dtOne
-------------------------
  ID  |   Name 
--------------------------
 101  |  ABC
 102  |  XYZ
 103  |  MNO
--------------------------

dtTwo
-------------------------
  ID  |   Name 
--------------------------
 101  |  ABC
 102  |  XYZ
--------------------------

I just want the result as data which is in dtOne and not in dtTwo (dtOne-dtTwo)

dtResult
-------------------------
  ID  |   Name 
--------------------------
 103  |  MNO
--------------------------

How can i achieve this .

0

2 Answers 2

20

TO get it work its better to use Linq To DataSet will resolve it easily..

DataTable table1= ds.Tables["table1"];
DataTable table2= ds.Tables["table2"];
var diff= table1.AsEnumerable().Except(table2.AsEnumerable(),
                                                    DataRowComparer.Default);
Sign up to request clarification or add additional context in comments.

Comments

2

Starting with the solution showed under LINQ query on a DataTable, I'd try it with:

var dtOneData = from myRow in dtOne.AsEnumerable();
var dtTwoData = from myRow in dtOne.AsEnumerable();
var difference = dtOneData.Except(dtTwoData);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.