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. More than one table in DataSet

More than one table in DataSet

Scheduled Pinned Locked Moved C#
question
8 Posts 5 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.
  • M Offline
    M Offline
    Mazdak
    wrote on last edited by
    #1

    DataSet has has Tables propety which means it can hold more than one table. How can I add second table to dataset.In dataadapetr I can use a select commmand which get one table,how can i add two table so? Mazy No sig. available now.

    N J 2 Replies Last reply
    0
    • M Mazdak

      DataSet has has Tables propety which means it can hold more than one table. How can I add second table to dataset.In dataadapetr I can use a select commmand which get one table,how can i add two table so? Mazy No sig. available now.

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      Mazy, try something like this:

      DataSet ds = new DataSet("myDataSet");
      DataTable t1 = new DataTable("Table1");
      DataTable t2 = new DataTable("Table2");

      ds.Tables.Add(t1);
      ds.Tables.Add(t2);

      HTH -Nick Parker

      M 1 Reply Last reply
      0
      • N Nick Parker

        Mazy, try something like this:

        DataSet ds = new DataSet("myDataSet");
        DataTable t1 = new DataTable("Table1");
        DataTable t2 = new DataTable("Table2");

        ds.Tables.Add(t1);
        ds.Tables.Add(t2);

        HTH -Nick Parker

        M Offline
        M Offline
        Mazdak
        wrote on last edited by
        #3

        Thanks Nick,I should get table from database,.Should I use second dataadpater to fill the same dataset with second table or there is better way for it? Mazy No sig. available now.

        M A 2 Replies Last reply
        0
        • M Mazdak

          Thanks Nick,I should get table from database,.Should I use second dataadpater to fill the same dataset with second table or there is better way for it? Mazy No sig. available now.

          M Offline
          M Offline
          Meysam Mahfouzi
          wrote on last edited by
          #4

          Actually we use each DataAdapter to populate or edit only one table(with 4 associated delete, update, insert and select commands). So, for inserting more than one table into a dataset, usually we use more than one DataAdapter.


          Don't forget, that's

          Persian Gulf

          not Arabian gulf!

          1 Reply Last reply
          0
          • M Mazdak

            Thanks Nick,I should get table from database,.Should I use second dataadpater to fill the same dataset with second table or there is better way for it? Mazy No sig. available now.

            A Offline
            A Offline
            Andres Manggini
            wrote on last edited by
            #5

            Hi, You can write a sql statement like this returning two tables: "SELECT * FROM People; SELECT * FROM Street;" That will populate two different tables on your DataSet, the first one containing all the people, and the second one with streets. Hope this helps. Andres Manggini. Buenos Aires - Argentina.

            M 1 Reply Last reply
            0
            • A Andres Manggini

              Hi, You can write a sql statement like this returning two tables: "SELECT * FROM People; SELECT * FROM Street;" That will populate two different tables on your DataSet, the first one containing all the people, and the second one with streets. Hope this helps. Andres Manggini. Buenos Aires - Argentina.

              M Offline
              M Offline
              Mazdak
              wrote on last edited by
              #6

              Andres Manggini wrote: "SELECT * FROM People; SELECT * FROM Street;" Oh,thats nice,can I run large SQL script like this? Mazy No sig. available now.

              1 Reply Last reply
              0
              • M Mazdak

                DataSet has has Tables propety which means it can hold more than one table. How can I add second table to dataset.In dataadapetr I can use a select commmand which get one table,how can i add two table so? Mazy No sig. available now.

                J Offline
                J Offline
                james cxx
                wrote on last edited by
                #7

                Try it once with the IDE/Form Designer first: drag a dataAdapter to the form and configure it. Such as "SELECT * FROM Projects". drag another dataAdapter to the form and configure it. Such as "SELECT * FROM People". Now right-click the first dataAdapter icon and choose Generate Dataset. In the form that pops-up choose New Dataset, and name the dataset something like DSAll. This is actually the schema name, but a dataset will be created, named like dsAll1. Now right-click the "other" dataAdpater and choose Generate Dataset. This time, choose "Existing Dataset" and select the dataset you just created. Then you have two dataAdapters (one for each table) which both update data in a single dataset (which contains two tables). You can then look over the Designer generated code to see what it did.

                M 1 Reply Last reply
                0
                • J james cxx

                  Try it once with the IDE/Form Designer first: drag a dataAdapter to the form and configure it. Such as "SELECT * FROM Projects". drag another dataAdapter to the form and configure it. Such as "SELECT * FROM People". Now right-click the first dataAdapter icon and choose Generate Dataset. In the form that pops-up choose New Dataset, and name the dataset something like DSAll. This is actually the schema name, but a dataset will be created, named like dsAll1. Now right-click the "other" dataAdpater and choose Generate Dataset. This time, choose "Existing Dataset" and select the dataset you just created. Then you have two dataAdapters (one for each table) which both update data in a single dataset (which contains two tables). You can then look over the Designer generated code to see what it did.

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

                  Thanks :) Mazy No sig. available now.

                  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