How to combine two DataTables with different schemas?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rhvintern
    New Member
    • Feb 2008
    • 1

    How to combine two DataTables with different schemas?

    I am working with C# code on an ASP.NET Page, and am having trouble with my DataTables. I have populated two tables from sprocs in my Database - the first one looks like this:
    Table1:
    ID Name
    id1 category1
    id2 category2

    my second table has multiple rows, but the relevant ones are:
    Table2:
    Name ID ParentID
    row1 id4 id1
    row2 id5 id1
    row3 id6 id2

    I want to display a table that will look something like this (pseudocode):

    foreach (t1row in Table1)
    {display t1row[name]
    foreach (t2row in Table2)
    { if (t2row[parentID] = t1row[id])
    {display t2row[all columns]}
    }
    }

    I have been trying to add or import these rows into a Display Table, or View, or even dataset, and it is not working. Any suggestions?

    Thank you!
    --student intern
  • dip_developer
    Recognized Expert Contributor
    • Aug 2006
    • 648

    #2
    Originally posted by rhvintern
    I am working with C# code on an ASP.NET Page, and am having trouble with my DataTables. I have populated two tables from sprocs in my Database - the first one looks like this:
    Table1:
    ID Name
    id1 category1
    id2 category2

    my second table has multiple rows, but the relevant ones are:
    Table2:
    Name ID ParentID
    row1 id4 id1
    row2 id5 id1
    row3 id6 id2

    I want to display a table that will look something like this (pseudocode):

    foreach (t1row in Table1)
    {display t1row[name]
    foreach (t2row in Table2)
    { if (t2row[parentID] = t1row[id])
    {display t2row[all columns]}
    }
    }

    I have been trying to add or import these rows into a Display Table, or View, or even dataset, and it is not working. Any suggestions?

    Thank you!
    --student intern
    from your query I understood that you want all the Name from Table1 and all the records from Table2 where Table2.ParentID =Table1.ID ...right???

    these two query will produce different number of records.....why do you want to join them....and on what basis......
    execute two different queries........
    1.select Name from Table1
    2.select Name, ID, ParentID from Table2 inner join Table1 on Table2.ParentID =Table1.ID

    Comment

    Working...