Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to create a DataSet with two tables having a 'JOIN' in ADO.NET?

How to create a DataSet with two tables having a 'JOIN' in ADO.NET?

Scheduled Pinned Locked Moved C#
tutorialcsharphelpquestion
10 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PravinSingh
    wrote on last edited by
    #1

    I want to create a DataSet that has two tables which are connected by a LEFT JOIN. All MSDN examples tell that if two tables are connected by a parent-child relation, I can add the two tables to DataSet object, create a DataRelation object by passing (parent, child) as parameters, and then add the DataRelation to the DataSet. But no example tells how to relate the tables if they are connected by a JOIN. I don't think we can create DataRelation for JOINs. If we can, how? And how to differentiate between JOIN, LEFT JOIN, FULL JOIN etc. while creating DataRelation? Any help is appreciated.


    It's better to know some of the questions than all of the answers.
    Pravin.

    OriginalGriffO F P T 4 Replies Last reply
    0
    • P PravinSingh

      I want to create a DataSet that has two tables which are connected by a LEFT JOIN. All MSDN examples tell that if two tables are connected by a parent-child relation, I can add the two tables to DataSet object, create a DataRelation object by passing (parent, child) as parameters, and then add the DataRelation to the DataSet. But no example tells how to relate the tables if they are connected by a JOIN. I don't think we can create DataRelation for JOINs. If we can, how? And how to differentiate between JOIN, LEFT JOIN, FULL JOIN etc. while creating DataRelation? Any help is appreciated.


      It's better to know some of the questions than all of the answers.
      Pravin.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Try the Database forum?

      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      P M 2 Replies Last reply
      0
      • P PravinSingh

        I want to create a DataSet that has two tables which are connected by a LEFT JOIN. All MSDN examples tell that if two tables are connected by a parent-child relation, I can add the two tables to DataSet object, create a DataRelation object by passing (parent, child) as parameters, and then add the DataRelation to the DataSet. But no example tells how to relate the tables if they are connected by a JOIN. I don't think we can create DataRelation for JOINs. If we can, how? And how to differentiate between JOIN, LEFT JOIN, FULL JOIN etc. while creating DataRelation? Any help is appreciated.


        It's better to know some of the questions than all of the answers.
        Pravin.

        F Offline
        F Offline
        fjdiewornncalwe
        wrote on last edited by
        #3

        I agree this is more of a db question, but you're answer may not lie in thinking of the dataset as two tables. The underlying query will contain a join, but the dataset will still only contain a single result set table.

        1 Reply Last reply
        0
        • P PravinSingh

          I want to create a DataSet that has two tables which are connected by a LEFT JOIN. All MSDN examples tell that if two tables are connected by a parent-child relation, I can add the two tables to DataSet object, create a DataRelation object by passing (parent, child) as parameters, and then add the DataRelation to the DataSet. But no example tells how to relate the tables if they are connected by a JOIN. I don't think we can create DataRelation for JOINs. If we can, how? And how to differentiate between JOIN, LEFT JOIN, FULL JOIN etc. while creating DataRelation? Any help is appreciated.


          It's better to know some of the questions than all of the answers.
          Pravin.

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          A JOIN produces one table, not two.

          1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Try the Database forum?

            Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

            P Offline
            P Offline
            PravinSingh
            wrote on last edited by
            #5

            I thought about that before posting, but this one is more of an ADO.NET question than a database question, so thought I'll be in good company here. :) The DB forum doesn't have many 'programming' questions, but if I don't get any answer here, probably I'll try my luck there as well.


            It's better to know some of the questions than all of the answers.
            Pravin.

            1 Reply Last reply
            0
            • P PravinSingh

              I want to create a DataSet that has two tables which are connected by a LEFT JOIN. All MSDN examples tell that if two tables are connected by a parent-child relation, I can add the two tables to DataSet object, create a DataRelation object by passing (parent, child) as parameters, and then add the DataRelation to the DataSet. But no example tells how to relate the tables if they are connected by a JOIN. I don't think we can create DataRelation for JOINs. If we can, how? And how to differentiate between JOIN, LEFT JOIN, FULL JOIN etc. while creating DataRelation? Any help is appreciated.


              It's better to know some of the questions than all of the answers.
              Pravin.

              T Offline
              T Offline
              T M Gray
              wrote on last edited by
              #6

              Ignore the people who say this is a database question. They probably have never worked with a DataRelation object and don't realize that ADO.Net allows you to essentially create an entire relational database in a DataSet. The parent child relationships are determined by the cardinality of the two tables. If for every record in table A there can be many records in table B, then A is the parent and B is the child and vise versa. In the case of a left join, the table that may have nulls is always the child. In the case of a many-to-many relationship you should create two DataRelations, one in each direction.

              P 1 Reply Last reply
              0
              • T T M Gray

                Ignore the people who say this is a database question. They probably have never worked with a DataRelation object and don't realize that ADO.Net allows you to essentially create an entire relational database in a DataSet. The parent child relationships are determined by the cardinality of the two tables. If for every record in table A there can be many records in table B, then A is the parent and B is the child and vise versa. In the case of a left join, the table that may have nulls is always the child. In the case of a many-to-many relationship you should create two DataRelations, one in each direction.

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                And how does that answer the question?

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  Try the Database forum?

                  Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                  M Offline
                  M Offline
                  MKAdeel
                  wrote on last edited by
                  #8

                  DataSet ds = new DataSet(); DataTable dt1 = new DataTable(); dt1.Columns.Add("PK", typeof(int)); DataTable dt2 = new DataTable(); dt2.Columns.Add("FK", typeof(int)); DataRelation Join = new DataRelation("Join", dt1.Columns[0], dt2.Columns[0]); ds.Relations.Add(Join);

                  P P 2 Replies Last reply
                  0
                  • M MKAdeel

                    DataSet ds = new DataSet(); DataTable dt1 = new DataTable(); dt1.Columns.Add("PK", typeof(int)); DataTable dt2 = new DataTable(); dt2.Columns.Add("FK", typeof(int)); DataRelation Join = new DataRelation("Join", dt1.Columns[0], dt2.Columns[0]); ds.Relations.Add(Join);

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #9

                    Shouldn't you have replied against the OP rather than somebody questioning where the post should go?

                    I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

                    Forgive your enemies - it messes with their heads

                    My blog | My articles | MoXAML PowerToys | Onyx

                    1 Reply Last reply
                    0
                    • M MKAdeel

                      DataSet ds = new DataSet(); DataTable dt1 = new DataTable(); dt1.Columns.Add("PK", typeof(int)); DataTable dt2 = new DataTable(); dt2.Columns.Add("FK", typeof(int)); DataRelation Join = new DataRelation("Join", dt1.Columns[0], dt2.Columns[0]); ds.Relations.Add(Join);

                      P Offline
                      P Offline
                      PravinSingh
                      wrote on last edited by
                      #10

                      This is exactly what all the MSDN examples show. My questions are: 1. This code is for the case where we have a query like "SELECT something FROM dt1, dt2 WHERE dt1.PK=dt2.FK". Will this also hold good for a query like "SELECT something FROM dt1 JOIN dt2 on (dt1.PK=dt2.FK)"? 2. How does the statement DataRelation Join = new DataRelation("Join", dt1.Columns[0], dt2.Columns[0]); change if in case of a JOIN, I have a FULL JOIN, or a LEFT JOIN, or an OUTER JOIN etc.?


                      It's better to know some of the questions than all of the answers.
                      Pravin.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups