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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:02:40+00:00 2026-05-12T08:02:40+00:00

I have 2 DataTables in vb.net. Each is populated from it’s own stored procedure.

  • 0

I have 2 DataTables in vb.net. Each is populated from it’s own stored procedure. Table A contains a project number in the first column. Table B also contains the project number in the first column. Table A could have many records that have the same project number, but Table B will always have just one record in it per project number. I would like to append the data from Table B to every matching record in Table A. How would I do this?

Table A could look like this:

PROJECT#, QUANTITY

12345, 100

12345, 200

12345, 300

Table B could look like this:

PROJECT#, CUSTOMER

12345, ABC Inc.

I would like to merge the two to create something like this:

PROJECT#, QUANTITY, CUSTOMER

12345, 100, ABC Inc.

12345, 200, ABC Inc.

12345, 300, ABC Inc.

Please help!

  • 1 1 Answer
  • 3 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-12T08:02:40+00:00Added an answer on May 12, 2026 at 8:02 am

    This may help you, and may be semi-generic enough to be applied to other situations.

    It’s a function that will merge the data (as per your example) by passing in the two tables, two arrays containing the column names you require from each table, and the key used to join the tables.

    There is an assumption that tblA is the driving table, with a lookup into tblB.

       Sub Main()
    
          Dim tbl As DataTable
    
          Dim colsA() As String = {"ProjectNo", "Quantity"}
          Dim colsB() As String = {"Customer"}
          Dim sKey As String = "ProjectNo"
    
          tbl = MergeData(tblA, tblB, colsA, colsB, sKey)
    
       End Sub
    
       Private Function MergeData(ByVal tblA As DataTable, ByVal tblB As DataTable, _
                                  ByVal colsA() As String, ByVal colsB() As String, _
                                  ByVal sKey As String) As DataTable
    
          Dim tbl As DataTable
          Dim col As DataColumn
          Dim sColumnName As String
          Dim row As DataRow
          Dim newRow As DataRow
          Dim dv As DataView
    
          tbl = New DataTable
          dv = tblB.DefaultView
    
          For Each sColumnName In colsA
             col = tblA.Columns(sColumnName)
             tbl.Columns.Add(New DataColumn(col.ColumnName, col.DataType))
          Next
          For Each sColumnName In colsB
             col = tblB.Columns(sColumnName)
             tbl.Columns.Add(New DataColumn(col.ColumnName, col.DataType))
          Next
    
          For Each row In tblA.Rows
             newRow = tbl.NewRow
             For Each sColumnName In colsA
                newRow(sColumnName) = row(sColumnName)
             Next
    
             dv.RowFilter = (sKey & " = " & row(sKey).ToString)
             If dv.Count = 1 Then
                For Each sColumnName In colsB
                   newRow(sColumnName) = dv(0).Item(sColumnName)
                Next
             End If
             tbl.Rows.Add(newRow)
          Next
    
          Return tbl
    
       End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the data table from the jquery plugin dataTables (http://datatables.net/) that I want
I have populated a DataTable from a stored procedure in an older web application
Suppose I have two .NET DataTables populated as follows, where ID is the primary
I have two datatables and I need to match zipcodes from each of the
I am using datatables. ( http://datatables.net/ ) I have created a table. There is
Using .NET 1.1, I have a DataGrid that contains three columns for each row.
EDIT: I am using VS2008, .NET 3.5 I have a DataTable, which is populated
I have two datatables. Each has three columns, the two of them have the
I have two datatables. One is to display names. Another contains three <h:selectOneMenu> .
I have an ASP.NET GridView that has four columns. The first three are typical

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.