Results 1 to 6 of 6

Thread: [2005] Fill a datatable with the contents of 3 other data tables

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    [2005] Fill a datatable with the contents of 3 other data tables

    Hello,

    I have one data table with fields SerialNo, manufacturer, and model. Called AllParts.

    I have 3 other data tables (software, components, equipment) that have those same fields plus some extra fields.

    I want to fill this allParts with the serialNo, manufacturer, and model from the other tables.

    So allParts will contain rows from software, components, equipment

    a bit like copying all the contents from the 3 tables and merging them into a single data table called allParts.

    Can anyone help me with this.

    Many thanks,

    Steve
    steve

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Fill a datatable with the contents of 3 other data tables

    Just loop through the rows of a source table and call the LoadDataRow method of the destination table. Do that three times and you're done.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: [2005] Fill a datatable with the contents of 3 other data tables

    Hello,

    Not sure which method is better but I did it this way.

    Code:
    dtAllCustomerPart.Merge(dtCustomersSoftware)
                dtAllCustomerPart.Merge(dtCustomersComponents)
                dtAllCustomerPart.Merge(dtCustomersEquipment)
    Thanks for any advice on this,
    steve

  4. #4
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Fill a datatable with the contents of 3 other data tables

    No advice just a question if you don't mind (I'm learning this and need to do something similar).

    Did you create 3 new datasets and merge them into a summary dataset? Or are they tables? I'm confused by all this and am just trying to get it straight in my head.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Fill a datatable with the contents of 3 other data tables

    Quote Originally Posted by steve_rm
    Hello,

    Not sure which method is better but I did it this way.

    Code:
    dtAllCustomerPart.Merge(dtCustomersSoftware)
                dtAllCustomerPart.Merge(dtCustomersComponents)
                dtAllCustomerPart.Merge(dtCustomersEquipment)
    Thanks for any advice on this,
    If that works then that would definitely be a better way. I wasn't aware that you could merge tables with different schema. I guess just the corresponding columns are used and the rest are ignored.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: [2005] Fill a datatable with the contents of 3 other data tables

    Hello Stimbo,

    I used 1 dataset and 4 data tables. The dataset can hold many data tables.

    I merged 3 data tables into 1 datatable.

    Hope this helps,

    Steve
    steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width