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 6119319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:32:20+00:00 2026-05-23T15:32:20+00:00

Q: I have two data tables and i wanna to inner join the and

  • 0

Q:

I have two data tables and i wanna to inner join the and return the result in a another datatable through LINQ.

DataTable dt1 = StaffCVDAL.getCourses(int.Parse(Session["emp_num"].ToString()));
DataTable dt2 = cc1lectcrsfilesDAL.ListFiles(int.Parse(Session["emp_num"].ToString()), int.Parse(Session["permission_code"].ToString()));
DataTable dt = from t1 in dt1.AsEnumerable()
               join t2 in dt2.AsEnumerable()
                      on t1["crsnum"] equals t2["crsnum"]
               select new { t1["crsname"],t2["group"] }; //the problem is here .
  • 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-05-23T15:32:21+00:00Added an answer on May 23, 2026 at 3:32 pm

    The problem is that the query expression (LINQ) returns an IEnumerable of the anonymous type you created, instead of a DataTable. IMHO, I prefer working with collections instead of datatables, but if you want to have a DataTable, you can create and populate it yourself from the collection, like this:

    var collection = from t1 in dt1.AsEnumerable()
                     join t2 in dt2.AsEnumerable()
                        on t1["crsnum"] equals t2["crsnum"]
                     select new { Name = t1["crsname"], Group = t2["group"] }; 
    DataTable result = new DataTable("NameGroups");
    result.Columns.Add("crsname", typeof(string));
    result.Columns.Add("group", typeof(int));
    
    foreach (var item in collection)
    {
       result.Rows.Add(item.Name, item.Group);
    }
    

    for more details, and a more general solution, take a look at this.

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

Sidebar

Related Questions

I have two data tables, dt1 & dt2. dt1 has data while dt2 is
I have two data tables and would like to join the two tables to
I am using Windows Application. I have two data tables called dt1 and dt2.
Q: I have two queries each one return a DataTable . I wanna to
i have two data tables with the same structure the first one has one
I have a database with two tables: data and file . file_id is a
I have two Tables: Table 1: Questions : QuestionId NUMERIC Title TEXT Test Data
I have two tables set up in phpmyadmin- table userid and table data. The
I have two different tables from which I need to pull data blogs which
I have two similar tables table_a and table_b table_a is my current data and

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.