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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Returning Multiple Tables from Stored Procedure

Returning Multiple Tables from Stored Procedure

Scheduled Pinned Locked Moved Database
tutorialcsharpsharepointdatabasehelp
4 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.
  • C Offline
    C Offline
    Craig G Fraser
    wrote on last edited by
    #1

    Hi, Does anyone know how to return muliple tables from a stored procedure to an .Net Application. For example if my sp has 3 separate select statements I want to return a dataset containing 3 tables with the results of the 3 select statements. Any help would be greatly appreciated. Cheers, Craig ** I'd rather try and fail than fail to try ;) **

    C M P 3 Replies Last reply
    0
    • C Craig G Fraser

      Hi, Does anyone know how to return muliple tables from a stored procedure to an .Net Application. For example if my sp has 3 separate select statements I want to return a dataset containing 3 tables with the results of the 3 select statements. Any help would be greatly appreciated. Cheers, Craig ** I'd rather try and fail than fail to try ;) **

      C Offline
      C Offline
      chinnasrihari
      wrote on last edited by
      #2

      Hi Create a SP that contains 3 SP (all there should return out put) generate typed dataset and drag and leave the SP on the data set you can see the three tables created on the typed dataset. Or else if you are not using typed dataset. and you are filling to simple data set, after filling data set use like someDataSet.Tables(0) someDataSet.Tables(1) someDataSet.Tables(2) to access the tables data Chinna Srihari Tech Lead, Capgemini

      1 Reply Last reply
      0
      • C Craig G Fraser

        Hi, Does anyone know how to return muliple tables from a stored procedure to an .Net Application. For example if my sp has 3 separate select statements I want to return a dataset containing 3 tables with the results of the 3 select statements. Any help would be greatly appreciated. Cheers, Craig ** I'd rather try and fail than fail to try ;) **

        M Offline
        M Offline
        Michael Potter
        wrote on last edited by
        #3

        DataSets are perfectly capable of handling multiple tables. There is no difference in acquiring multiple tables from a stored proc as there is in acquiring one table. In your case:

        DataSet ds = new DataSet();
        // ... Call stored proc
        Console.WriteLine("Table 1 Rows: " + ds.Tables[0].Rows.Count().ToString();
        Console.WriteLine("Table 2 Rows: " + ds.Tables[1].Rows.Count().ToString();
        Console.WriteLine("Table 3 Rows: " + ds.Tab;es[2].Rows.Count().ToString();
        
        1 Reply Last reply
        0
        • C Craig G Fraser

          Hi, Does anyone know how to return muliple tables from a stored procedure to an .Net Application. For example if my sp has 3 separate select statements I want to return a dataset containing 3 tables with the results of the 3 select statements. Any help would be greatly appreciated. Cheers, Craig ** I'd rather try and fail than fail to try ;) **

          P Offline
          P Offline
          Paul Brower
          wrote on last edited by
          #4

          The following would return three RESULTSETS from sql server: SELECT * FROM CUSTOMER SELECT * FROM INVOICE SELECT * FROM INVOICE_DETAIL through a SqlCommand object and a SqlDataAdapter you can fill a dataset with the resultset. If you're using a strongly-typed dataset, make sure to set the table mappings. I could have been a little more detailed, but it's all in the MSDN help.

          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