Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Merge two tables

Merge two tables

Scheduled Pinned Locked Moved C#
csharpquestion
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xoxoxoxoxoxox
    wrote on last edited by
    #1

    I want two merge two tables A & B. Table-A contains column A, B, C and Table-B contains column D, E, F. I want the result table to contain columns from both tables i.e., A,B,C,D,E,F. Is there a way to accomplish this in C#? I'll greatly appreciate any response.

    C J 2 Replies Last reply
    0
    • X xoxoxoxoxoxox

      I want two merge two tables A & B. Table-A contains column A, B, C and Table-B contains column D, E, F. I want the result table to contain columns from both tables i.e., A,B,C,D,E,F. Is there a way to accomplish this in C#? I'll greatly appreciate any response.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      How do rows in the two columns map to each other, so that such a join makes sense ? Where are the tables coming from ? The most sensible thing would be to write SQL to return a table that merges the two tables together, assuming there's a way of doing that logically.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      1 Reply Last reply
      0
      • X xoxoxoxoxoxox

        I want two merge two tables A & B. Table-A contains column A, B, C and Table-B contains column D, E, F. I want the result table to contain columns from both tables i.e., A,B,C,D,E,F. Is there a way to accomplish this in C#? I'll greatly appreciate any response.

        J Offline
        J Offline
        J 0
        wrote on last edited by
        #3

        I assume that you're saying you want to merge 2 System.Data.DataTable objects into one. If thats not the case forgive me... If this data is coming from 2 separate, but related tables in your database, you can add them to a DataSet, and set up a DataRelation between the 2 tables. This doesn't merge the 2 tables into 1, but it will allow you to retrieve the data for a particular DataRow in DataTable1, as well as the DataRows from DataTable2 that are related to it. You can get the related row information by calling dataRow.GetChildRows(), dataRow.GetParentRow(), or dataRow.GetParentRows() Hope that helps...

        X 1 Reply Last reply
        0
        • J J 0

          I assume that you're saying you want to merge 2 System.Data.DataTable objects into one. If thats not the case forgive me... If this data is coming from 2 separate, but related tables in your database, you can add them to a DataSet, and set up a DataRelation between the 2 tables. This doesn't merge the 2 tables into 1, but it will allow you to retrieve the data for a particular DataRow in DataTable1, as well as the DataRows from DataTable2 that are related to it. You can get the related row information by calling dataRow.GetChildRows(), dataRow.GetParentRow(), or dataRow.GetParentRows() Hope that helps...

          X Offline
          X Offline
          xoxoxoxoxoxox
          wrote on last edited by
          #4

          Thank you very much for your response. Yes, i want to merge 2 DataTable objects into one. I'll try the method you suggested. Thanks again.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups