Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8114771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:15:07+00:00 2026-06-06T03:15:07+00:00

if i have two datatables : DT1 & DT2 How to check if the

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:15:09+00:00Added an answer on June 6, 2026 at 3:15 am

    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 DataTables are null or both have the same row-count. Then you can use LINQ to determine if both have the same IDs using Enumerable.Except:

    var dt1IDs = DT1.AsEnumerable().Select(r => r.Field<int>("id"));
    var dt2IDs = DT2.AsEnumerable().Select(r => r.Field<int>("id"));
    var diff = dt1IDs.Except(dt2IDs);
    var equal = DT1.Rows.Count == DT2.Rows.Count && !diff.Any();
    

    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:

    var DT1InDT2 = dt1IDs.Except(dt2IDs);
    var DT2InDT1 = dt2IDs.Except(dt1IDs);
    var equal = DT1.Rows.Count == DT2.Rows.Count && !DT1InDT2.Any() && !DT2InDT1.Any();
    

    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.

    var DT2IdNotInDT1 = dt2IDs.Except(dt1IDs);
    var equal = !DT2IdNotInDT1.Any();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two DataTables e.g., dt1 and dt2. dt1 contains the list of all
I have two datatables. One is to display names. Another contains three <h:selectOneMenu> .
i have two data tables with the same structure the first one has one
Let's say I have two DataTables DT1 and DT2 with a single row. DT1
I have two datatables dt1 and dt2 i copied dt2 into dt1 and clear
I have two DataTables: dt1 - personid, name dt2 - personid I want to
I have two DataTable [System.Data] .One contains three rows id,name,date and another contains id
I have two DataTables dt1 and dt2. Each table have different data in them
Q: If I have two DataTables like this : Dt1 (emp_num,emp_name,type) Dt2 (emp_num,emp_name,type) I
I have two datatables one has few rows other is empty. I am running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.