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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:39:25+00:00 2026-06-03T10:39:25+00:00

I’m trying to join two DataTables together in a similar way to this question:

  • 0

I’m trying to join two DataTables together in a similar way to this question:

Inner join of DataTables in C#

I’m trying to get the output to be a single ‘combined’ table, with columns from both of the original tables. They will both have a datestamp column in common.

The answer given is good for DataTables with fixed columns, but what if they are created dynamically, and can have any number of columns, how can I join them?

e.g.

T1 (datestamp, t1Column1, t1Column2, t1ColumnN...)
T2 (datestamp, t2Column1, t2Column2, t2ColumnN...)

I would like to join to create the following:

J1 (datestamp, t1Column1, t1Column2, t1ColumnN, ..., t2Column1, t2Column2, t2ColumnN...)

Is this possible?

  • 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-03T10:39:27+00:00Added an answer on June 3, 2026 at 10:39 am

    I found a solution which doesn’t rely on looping through the columns.

    It uses the ‘Merge’ method, which I had previously dismissed as I thought both tables required the same structure.

    First you need to create a primary key on the two data-tables:

    // set primary key
    T1.PrimaryKey = new DataColumn[] { T1.Columns["DateStamp"] };
    T2.PrimaryKey = new DataColumn[] { T2.Columns["DateStamp"] };
    

    Then add both tables to a data-set so a relationship can be added:

    // add both data-tables to data-set
    DataSet dsContainer = new DataSet();
    dsContainer.Tables.Add(T1);
    dsContainer.Tables.Add(T2);
    

    Next add the relationship between the two key columns in the data-set:

    // add a relationship between the two timestamp columns
    DataRelation relDateStamp = new DataRelation("Date", new DataColumn[] { T1.Columns["DateStamp"] }, new DataColumn[] { T2.Columns["DateStamp"] });
    dsContainer.Relations.Add(relDateStamp);
    

    Finally you can now copy the first data-table into a new ‘combined’ version, and then merge in the second:

    // populate combined data
    DataTable dtCombined = new DataTable();
    dtCombined = T1.Copy();
    dtCombined.Merge(T2, false, MissingSchemaAction.Add);
    

    Note: The Merge method requires the second argument to be false or else it copies the structure but not the data of the second table.

    This would then combine the following tables:

    T1 (2012-05-09, 111, 222)
    T2 (2012-05-09, 333, 444, 555)
    

    into a combined version based on the primary-key:

    J1 (2012-05-09, 111, 222, 333, 444, 555)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

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.