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. Fill DataSet with two tables

Fill DataSet with two tables

Scheduled Pinned Locked Moved C#
tutorial
11 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.
  • R Offline
    R Offline
    Rahul DSG
    wrote on last edited by
    #1

    How to fill a dataset using two tables coz i want to use that dataset for crystal report.

    L M P 3 Replies Last reply
    0
    • R Rahul DSG

      How to fill a dataset using two tables coz i want to use that dataset for crystal report.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      DataTable table1 = new DataTable(); DataTable table2 = new DataTable(); DataSet dataSet = new DataSet(); dataSet.Tables.Add(table1); dataSet.Tables.Add(table2);

      R 1 Reply Last reply
      0
      • R Rahul DSG

        How to fill a dataset using two tables coz i want to use that dataset for crystal report.

        M Offline
        M Offline
        Mike Ellison
        wrote on last edited by
        #3

        DataAdapter.Fill perhaps? If you're using SQL Server for your database, you can call a stored procedure that returns two result sets - each will be filled in the dataset as a separate DataTable. The stored procedure is simple:

        CREATE PROCEDURE Sample
        AS
        BEGIN
        select * from table1;
        select * from table2;
        END

        MishaInTheCloud.blogspot.com

        R 1 Reply Last reply
        0
        • L Lost User

          DataTable table1 = new DataTable(); DataTable table2 = new DataTable(); DataSet dataSet = new DataSet(); dataSet.Tables.Add(table1); dataSet.Tables.Add(table2);

          R Offline
          R Offline
          Rahul DSG
          wrote on last edited by
          #4

          the code is like this.. SqlCommand cmd; SqlConnection conn; SqlDataAdapter sda; conn = new SqlConnection("server=Sai2; database=Inventory; uid=sa; pwd=123456;"); cmd = conn.CreateCommand(); cmd.CommandText = "select * from stock"; sda = new SqlDataAdapter(); sda.SelectCommand = cmd; DataS.Stock ds = new SisInventorySystem.DataS.Stock(); sda.Fill(ds, "stock"); Crystal_Reports.TotalStockRpt TtlStkRpt = new SisInventorySystem.Crystal_Reports.TotalStockRpt(); TtlStkRpt.SetDataSource(ds); crystalReportViewer1.ReportSource = TtlStkRpt; crystalReportViewer1.DisplayToolbar = true; Now i have to run one more Query "select * from Company" having nothing in common between table company and stock.

          R 1 Reply Last reply
          0
          • R Rahul DSG

            How to fill a dataset using two tables coz i want to use that dataset for crystal report.

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

            With SQL Server: "SELECT * FROM Table1 ; SELECT * FROM Table2" (Other database engines don't allow multiple statements in a command.)

            1 Reply Last reply
            0
            • R Rahul DSG

              the code is like this.. SqlCommand cmd; SqlConnection conn; SqlDataAdapter sda; conn = new SqlConnection("server=Sai2; database=Inventory; uid=sa; pwd=123456;"); cmd = conn.CreateCommand(); cmd.CommandText = "select * from stock"; sda = new SqlDataAdapter(); sda.SelectCommand = cmd; DataS.Stock ds = new SisInventorySystem.DataS.Stock(); sda.Fill(ds, "stock"); Crystal_Reports.TotalStockRpt TtlStkRpt = new SisInventorySystem.Crystal_Reports.TotalStockRpt(); TtlStkRpt.SetDataSource(ds); crystalReportViewer1.ReportSource = TtlStkRpt; crystalReportViewer1.DisplayToolbar = true; Now i have to run one more Query "select * from Company" having nothing in common between table company and stock.

              R Offline
              R Offline
              Robin_Roy
              wrote on last edited by
              #6

              You can write a stored procedure that returns multiple recordset and get the resultset directly mapped with a dataset, it will create the same number of datatables in your dataset as the count of resultset in your procedure...

              1 Reply Last reply
              0
              • M Mike Ellison

                DataAdapter.Fill perhaps? If you're using SQL Server for your database, you can call a stored procedure that returns two result sets - each will be filled in the dataset as a separate DataTable. The stored procedure is simple:

                CREATE PROCEDURE Sample
                AS
                BEGIN
                select * from table1;
                select * from table2;
                END

                MishaInTheCloud.blogspot.com

                R Offline
                R Offline
                Rahul DSG
                wrote on last edited by
                #7

                ok... and after what to write... da.fill(ds,"whichtable"); can i write the both table....

                M 1 Reply Last reply
                0
                • R Rahul DSG

                  ok... and after what to write... da.fill(ds,"whichtable"); can i write the both table....

                  M Offline
                  M Offline
                  Mike Ellison
                  wrote on last edited by
                  #8

                  Access the tables through the DataSet's Tables collection:

                  DataTable dt0 = ds.Tables[0]; // first result set from the batch queries
                  DataTable dt1 = ds.Tables[1]; // second result set from the batch queries

                  MishaInTheCloud.blogspot.com

                  R 1 Reply Last reply
                  0
                  • M Mike Ellison

                    Access the tables through the DataSet's Tables collection:

                    DataTable dt0 = ds.Tables[0]; // first result set from the batch queries
                    DataTable dt1 = ds.Tables[1]; // second result set from the batch queries

                    MishaInTheCloud.blogspot.com

                    R Offline
                    R Offline
                    Rahul DSG
                    wrote on last edited by
                    #9

                    Done All the things but can not Solved ... sda.fill(ds,"Table name Is Must.") Is there any Solution...

                    M 1 Reply Last reply
                    0
                    • R Rahul DSG

                      Done All the things but can not Solved ... sda.fill(ds,"Table name Is Must.") Is there any Solution...

                      M Offline
                      M Offline
                      Mike Ellison
                      wrote on last edited by
                      #10

                      Why is the table name a must upon filling? You can always change the table name (if you really need to) after filling the set like this:

                      sda.Fill(ds);
                      ds.Tables[0].TableName = "tableNameIsAMust.";
                      ds.Tables[1].TableName = "somethingElse";

                      Or is it that you are looking to execute two queries separately (instead of together in one batch)? In that case, you could supply separate table names upon filling:

                      da1.Fill(ds, "Table1");
                      da2.Fill(ds, "Table2");

                      I'm having difficulty understanding exactly why this is problematic for you. Can you explain?

                      www.MishaInTheCloud.com

                      R 1 Reply Last reply
                      0
                      • M Mike Ellison

                        Why is the table name a must upon filling? You can always change the table name (if you really need to) after filling the set like this:

                        sda.Fill(ds);
                        ds.Tables[0].TableName = "tableNameIsAMust.";
                        ds.Tables[1].TableName = "somethingElse";

                        Or is it that you are looking to execute two queries separately (instead of together in one batch)? In that case, you could supply separate table names upon filling:

                        da1.Fill(ds, "Table1");
                        da2.Fill(ds, "Table2");

                        I'm having difficulty understanding exactly why this is problematic for you. Can you explain?

                        www.MishaInTheCloud.com

                        R Offline
                        R Offline
                        Rahul DSG
                        wrote on last edited by
                        #11

                        Actually I have to make a crystal report which needs two table nothing is common in between these two tables.i tried all these suggestion in this section but not working...i already posted my code...

                        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