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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:54:12+00:00 2026-05-14T23:54:12+00:00

I have multiple datasets that I would like to combine into one. There is

  • 0

I have multiple datasets that I would like to combine into one. There is a common ID field that can be associated to each row. Calling Merge on the dataset will add additional rows to the dataset, but I would like to combine the additional columns. There are too many fields to do this in one query and therefore would make it unmanageable. Each individual query would be able to handle ordering to ensure the data is placed in the correct row.

For Example lets say I have two queries resulting in two datasets:

SELECT ID, colA, colB
SELECT colC, colD

The resulting dataset would look like

ID colA colB colC colD
1  a    b    c    d
2  e    f    g    h

Any ideas on ways to accomplish this?

  • 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-14T23:54:12+00:00Added an answer on May 14, 2026 at 11:54 pm

    Here is an example of how to accomplish what you want using ASP.NET and VB.NET. I created a “MergeColumns” and “MergeData” sub for you.

       Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            'Create the dataset and put in the data.  Normally you will just get this from a database query'
    
            Dim ds1 As New Data.DataSet
            Dim ds2 As New Data.DataSet
    
            Dim dt1 = ds1.Tables.Add()
            dt1.Columns.Add("ID", GetType(Int32))
            dt1.Columns.Add("ColA", GetType(String))
            dt1.Columns.Add("ColB", GetType(String))
    
            Dim dt2 = ds2.Tables.Add()
            dt2.Columns.Add("ColC", GetType(String))
            dt2.Columns.Add("ColD", GetType(String))
    
            dt1.Rows.Add(1, "a", "b")
            dt2.Rows.Add("c", "d")
            dt1.Rows.Add(2, "e", "f")
            dt2.Rows.Add("g", "h")
    
            'Sample data created, now to merge the results like you want'
            Dim dsNew As New Data.DataSet
            Dim dtNew = dsNew.Tables.Add(0)
    
            MergeColumns(dtNew, dt1, dt2)
            MergeData(dtNew, dt1, dt2)
    
            'Display the results'
            dsNew.AcceptChanges()
            Response.Write(dsNew.GetXml)
    
        End Sub
    
    
        Private Sub MergeColumns(ByVal TargetTable As Data.DataTable, ByVal ParamArray SourceTables() As Data.DataTable)
            For Each dtSource In SourceTables
                'Make a clone of the table, then steal the columns from the clone'
                Dim dtClone = dtSource.Clone
    
                While dtClone.Columns.Count > 0
                    Dim dc = dtClone.Columns(0)
    
                    dtClone.Columns.Remove(dc)
    
                    TargetTable.Columns.Add(dc)
                End While
            Next
        End Sub
    
    
        Private Sub MergeData(ByVal TargetTable As Data.DataTable, ByVal ParamArray SourceTables() As Data.DataTable)
            'Determine the number of rows the final table will have'
            Dim nMaxRowCount = 0
            For Each dt In SourceTables
                If dt.Rows.Count > nMaxRowCount Then
                    nMaxRowCount = dt.Rows.Count
                End If
            Next
    
            For i = 0 To nMaxRowCount - 1
                'Create a new row using column data from each table.  Assumes the name is unique across tables.'
                Dim drTarget = TargetTable.NewRow
                For Each dcTarget As Data.DataColumn In TargetTable.Columns
                    For Each dt In SourceTables
                        If i < dt.Rows.Count AndAlso dt.Columns.Contains(dcTarget.ColumnName) Then
                            drTarget(dcTarget) = dt.Rows(i)(dcTarget.ColumnName)
                        End If
                    Next
                Next
                TargetTable.Rows.Add(drTarget)
            Next
    
        End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple dl elements on a page. At the end of each one
I have multiple nested movieclip in its own different movieclip, and i would like
I have several tables in my ERD which which I would like to combine
I have multiple selects: <select id=one> <option value=1>one</option> <option value=2>two</option> <option value=3>three</option> </select> <select
I have multiple projects in a couple of different workspaces. However, it seems like
I have multiple classes that all derive from a base class, now some of
I have multiple threads (C# application running on IIS) running that all need to
I have multiple branches of a project checked out, each under their own directory
I have multiple logos of various companies in various formats that needs to be
I have multiple elements that have ID's (and names) in the form : id=foo[1]

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.