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. Database & SysAdmin
  3. Database
  4. single DataSet having multiple DataTables from multiple databases

single DataSet having multiple DataTables from multiple databases

Scheduled Pinned Locked Moved Database
question
6 Posts 4 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.
  • H Offline
    H Offline
    Hailu Worku Obsse
    wrote on last edited by
    #1

    It is possible to have a single DataSet having multiple DataTables from multiple databases. If so can you just tell me how ?

    Richard DeemingR M 2 Replies Last reply
    0
    • H Hailu Worku Obsse

      It is possible to have a single DataSet having multiple DataTables from multiple databases. If so can you just tell me how ?

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Yes it is.

      var ds = new DataSet();

      using (var connection = new SqlConnection("..."))
      {
      var da = new SqlDataAdapter("SELECT ...", connection);
      da.SelectCommand.Parameters.AddWithValue(...);
      da.Fill(ds, "FirstTable");
      }

      using (var connection = new OleDbConnection("..."))
      {
      var da = new OleDbDataAdapter("SELECT ...", connection);
      da.SelectCommand.Parameters.AddWithValue(...);
      da.Fill(ds, "SecondTable");
      }

      If one of your queries returns multiple result-sets, you might need to use TableMappings to specify the table names: DataAdapter DataTable and DataColumn Mappings | Microsoft Docs[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      H 1 Reply Last reply
      0
      • H Hailu Worku Obsse

        It is possible to have a single DataSet having multiple DataTables from multiple databases. If so can you just tell me how ?

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        Many years ago I experimented with SQL Server returning multiple tables from a single stored procedure. The performance was dramatically slower then return multiple single tables from individual stored procs. Performance may have changed in recent versions.

        Never underestimate the power of human stupidity RAH

        L 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          Yes it is.

          var ds = new DataSet();

          using (var connection = new SqlConnection("..."))
          {
          var da = new SqlDataAdapter("SELECT ...", connection);
          da.SelectCommand.Parameters.AddWithValue(...);
          da.Fill(ds, "FirstTable");
          }

          using (var connection = new OleDbConnection("..."))
          {
          var da = new OleDbDataAdapter("SELECT ...", connection);
          da.SelectCommand.Parameters.AddWithValue(...);
          da.Fill(ds, "SecondTable");
          }

          If one of your queries returns multiple result-sets, you might need to use TableMappings to specify the table names: DataAdapter DataTable and DataColumn Mappings | Microsoft Docs[^]


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          H Offline
          H Offline
          Hailu Worku Obsse
          wrote on last edited by
          #4

          Thank you for your replay .... however, I am looking different databases from the same provider

          Richard DeemingR 1 Reply Last reply
          0
          • H Hailu Worku Obsse

            Thank you for your replay .... however, I am looking different databases from the same provider

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            So load data from different databases from the same provider then. What's the problem?


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            1 Reply Last reply
            0
            • M Mycroft Holmes

              Many years ago I experimented with SQL Server returning multiple tables from a single stored procedure. The performance was dramatically slower then return multiple single tables from individual stored procs. Performance may have changed in recent versions.

              Never underestimate the power of human stupidity RAH

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

              MARS be slow, but selecting from a different DB is hardly noticable on SQL Server. Also doesn't need much mucking with datasets, just plain SQL.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

              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