SQL JOIN between DataTables in a DataSet

Last post 09-24-2007 9:36 AM by WolfyUK. 5 replies.

Sort Posts:

  • Confused [*-)] SQL JOIN between DataTables in a DataSet

    07-12-2007, 4:33 AM
    • Loading...
    • WolfyUK
    • Joined on 07-15-2005, 5:38 AM
    • Leeds, UK
    • Posts 32

    Hello,

    Am I correct in thinking that it is currently not possible to perform an SQL JOIN across multiple DataTables in a DataSet in .NET? I have a typed DataSet with three relational tables which need to be placed into one flat table, e.g.:

    Table A: PK, Table A Col 1, Table A Col 2...
    Table B: PK, FK 1 (Table A PK), FK 2 (Table C PK)
    Table C: PK, Table C Col 1, Table C Col 2...
    =>   PK, Table A Col 1, Table A Col 2, Table C Col 1, Table C Col 2

    Currently the only way to resolve this involves embedded for-loops going down each of the typed relations to get the required data. Obviously performing one SELECT statement would be far more efficient, but is this possible here?

    I only have access to this DataSet and so am unable to perform the join in the database before the DataSet is Filled.

    Thanks,

    Marc

    Filed under: , ,
  • Re: SQL JOIN between DataTables in a DataSet

    07-12-2007, 8:20 AM
    Answer
    • Loading...
    • SGWellens
    • Joined on 01-02-2007, 9:27 PM
    • MN, USA
    • Posts 3,398
    • Moderator
      TrustedFriends-MVPs

    WolfyUK:
    Am I correct in thinking that it is currently not possible to perform an SQL JOIN across multiple DataTables in a DataSet in .NET?
     

    Yes.   If you want to bind to a visual control, you could create, by hand, an additional table with the data and relationships.

    Steve Wellens
  • Re: SQL JOIN between DataTables in a DataSet

    07-12-2007, 9:09 AM
    • Loading...
    • WolfyUK
    • Joined on 07-15-2005, 5:38 AM
    • Leeds, UK
    • Posts 32

    Thanks. I've managed to find a slightly more efficient way to do this than with the embedded loops now as well. 

    Marc 

  • Re: SQL JOIN between DataTables in a DataSet

    07-17-2007, 9:26 AM
    • Loading...
    • PaulusDeM
    • Joined on 07-17-2007, 1:23 PM
    • Posts 1

    Would you mind sharing the solution with me? I'm am currently having the same problem.

     

    Thanks in advance,

     

    Paul

  • Re: SQL JOIN between DataTables in a DataSet

    09-17-2007, 6:11 AM
    • Loading...
    • lingz
    • Joined on 07-18-2007, 9:39 AM
    • Posts 30

    Yes, I have the same question.

  • Re: SQL JOIN between DataTables in a DataSet

    09-24-2007, 9:36 AM
    • Loading...
    • WolfyUK
    • Joined on 07-15-2005, 5:38 AM
    • Leeds, UK
    • Posts 32

    Sorry for the delayed reply. What I did was to loop through all of the rows in the 'intermediate table' and select the related rows from each of the related tables using the Select() method on both, providing the relevant foreign key values. A new typed 'intermediate table' row is then created from the two returned rows and added to a waiting DataSet.

    This seems to be efficient enough for our needs.

Page 1 of 1 (6 items)
Microsoft Communities
Page view counter