Lookup Multiple Datatables into 1 datatable-VBForums
Results 1 to 3 of 3

Thread: Lookup Multiple Datatables into 1 datatable

  1. #1

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Lookup Multiple Datatables into 1 datatable

    dt1
    Code:
    ID   Animal
    1    Monkey
    2    Cat
    3    Dog
    4    Fish
    dt2
    Code:
    ID   Activity
    1    Walk
    2    Swim
    3    Climb
    dtMain
    Code:
    ID   Animal   Activity   Comment
    1     1          3      Blah blah
    2     4          2      foobar
    I want to display....
    Code:
    ID   Animal   Activity   Comment
    1    Monkey   Climb       Blah blah
    2    Fish     Swim        foobar
    Hi there,

    I have a problem here, not sure how to tackle this one. I have a datatable (dtMain) which has columns which I want to replace the values in a datatable with the descriptor of the lookup tables.

    Anyone have any ideas at all? Is it even possible?

    Many many thanks in advance!
    If you find my thread helpful, please remember to rate me

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,219

    Re: Lookup Multiple Datatables into 1 datatable

    Would it not be better to just execute a query against the database and get the data in the format you want it in the first place? If not, you can perform a LINQ query to join the data in the two DataTables and then call CopyToDataTable to create a new DataTable containing the results.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  3. #3
    New Member
    Join Date
    Feb 2012
    Posts
    12

    Re: Lookup Multiple Datatables into 1 datatable

    Quote Originally Posted by jmcilhinney View Post
    Would it not be better to just execute a query against the database and get the data in the format you want it in the first place? If not, you can perform a LINQ query to join the data in the two DataTables and then call CopyToDataTable to create a new DataTable containing the results.
    I agree, making one query with proper joins will save you a lot of trouble later.

    If they're in different databases, you can always use a DB link

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.