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

  • SEARCH
  • Home
  • 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 8995975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:41:29+00:00 2026-06-15T23:41:29+00:00

I have two DataTables t1 and t2 . I’m trying to perform a LINQ

  • 0

I have two DataTables t1 and t2. I’m trying to perform a LINQ left join, multiple equijoin, to get the DataRows in t1 that are not in t2.

In SQL, what I’m trying to accomplish is:

select t1.* 
from t1
left join t2
on t1.a=t2.a and
   t1.b=t2.b and
   t1.c=t2.c
where
   t2.a is null

So far I have the following:

public DataTable t1_without_t2(DataTable t1, DataTable t2)
        {
            var query = from t1_row in t1.AsEnumerable()
                        join t2_row in t2.AsEnumerable()
                        on 
                        new { t_a = t1_row["a"], t_b = t1_row["b"], t_c = t1_row["c"]}   
                        equals
                        new { t_a = t2_row["a"], t_b = t2_row["b"], t_c = t2_row["c"]}
                        into leftJoinT1withoutT2
                        from join_row in leftJoinT1withoutT2.DefaultIfEmpty()
                        where t2_row["a"] == null
                        select new
                        {
                            j_a = join_row["a"],
                            j_b = join_row["b"],
                            j_c = join_row["c"],
                        };
            DataTable dt = t1.Clone();
            foreach (var result in query)
            {
                dt.LoadDataRow(
                    new object[]
                    {
                        result.j_a,
                        result.j_b,
                        result.j_c
                    },
                    false);
            }
            return dt;
        }

This is failing on the line j_a = join_row["a"] with this message:
Column 'a' does not belong to table.

I thought that the into leftJoinT1withoutT2 line was supposed to put the results of the join into a var with the column structure of table t1, from which the non-matching entries would be removed using where t2_row["a"] == null . Is that not what’s happening here? I’m a little confused.

  • 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-15T23:41:30+00:00Added an answer on June 15, 2026 at 11:41 pm

    It should look like this:

    var query = from t1_row in t1.AsEnumerable()
                join t2_row in t2.AsEnumerable()
                on
                new { t_a = t1_row["a"], t_b = t1_row["b"], t_c = t1_row["c"] }
                equals
                new { t_a = t2_row["a"], t_b = t2_row["b"], t_c = t2_row["c"] }
                into leftJoinT1withoutT2
                from join_row in leftJoinT1withoutT2.DefaultIfEmpty()
                                                    .Where(r => r == null)
                select new
                {
                    j_a = t1_row["a"],
                    j_b = t1_row["b"],
                    j_c = t1_row["c"],
                };
    

    Have a look at How to: Perform Left Outer Joins (C# Programming Guide).

    The join_row gets null (i.e. default TSource value, see Enumerable.DefaultIfEmpty) when there is no matching element in t2, while t1_row always contains the joined value. So as far as you need only those rows for which join_row is null, I used .Where(r => r == null).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple linq query that gets data from two datatables (orderHeader
I want to perform a JOIN on two Datatables in a Dataset. For example,
I have two DataTables. I want to do inner join them into a new
I have a report that needs to get data from two logical areas of
I'm trying to join two DataTables together in a similar way to this question:
I have two datatables that I am merging together using Javascript and jQuery. I
i have two datatables that i am inserting into sql server 2008 using SqlBulkCopy
I have two tables in SQL that I populate into DataTables in C#. They
I have a .NET application that is merging two datatables with a lot of
I have two datatables. Each has three columns, the two of them have the

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.