if i have two datatables :
DT1 & DT2
How to check if the first one contains the second one , i mean that the same rows of DT2 is in the DT1.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
My question: “Must all row’s fields match with the same row’s fields of the other DataTable?”
Your answer: “no just the id”
You can first check if both
DataTablesare null or both have the same row-count. Then you can use LINQ to determine if both have the same IDs usingEnumerable.Except:Explanation:
diff.Any()returns true when there’s at least one id in DT1 that is not in DT2.Edit: If the ID is not unique and might repeat you need to check whether all ID’s in DT1 are also in DT2 and all IDs of DT2 are in DT1:
This query is efficient anyway.
Edit2: I’ve just seen that i’ve misunderstood your requiremnet a little bit. You only want to know if the first table contains the second, not vice-versa.