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. Getting TableName in DataSet/DataTable from SP

Getting TableName in DataSet/DataTable from SP

Scheduled Pinned Locked Moved Database
questiondatabasesharepointsql-serversysadmin
4 Posts 3 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
    Maxim Langman
    wrote on last edited by
    #1

    Hello, I have a little Stored Procedure (SQL Server 2005), which returns some tables. Now, I'm getting those tables in the DataSet in my code. The problem is that I'm not getting TableName of none of the tables. All I get is a default naming convention "Table", Table1", Table2" .... What is the way to get the TableName from SP? How can I basically know which table represents which select in the SP? Thanks, Maxim

    Y S 2 Replies Last reply
    0
    • M Maxim Langman

      Hello, I have a little Stored Procedure (SQL Server 2005), which returns some tables. Now, I'm getting those tables in the DataSet in my code. The problem is that I'm not getting TableName of none of the tables. All I get is a default naming convention "Table", Table1", Table2" .... What is the way to get the TableName from SP? How can I basically know which table represents which select in the SP? Thanks, Maxim

      Y Offline
      Y Offline
      ya3mro
      wrote on last edited by
      #2

      i think you can view code of the dataset and search for tag name and you find inside it all tables data from database

      1 Reply Last reply
      0
      • M Maxim Langman

        Hello, I have a little Stored Procedure (SQL Server 2005), which returns some tables. Now, I'm getting those tables in the DataSet in my code. The problem is that I'm not getting TableName of none of the tables. All I get is a default naming convention "Table", Table1", Table2" .... What is the way to get the TableName from SP? How can I basically know which table represents which select in the SP? Thanks, Maxim

        S Offline
        S Offline
        sharad48
        wrote on last edited by
        #3

        CREATE PROCEDURE MyProc AS BEGIN Select 'FirstTableName' AS TableName, Column1, Column2 FROM FirstTable Select 'SecondTableName' AS TableName, Column1, Column2 FROM SecondTable Select 'ThirdTableName' AS TableName, * FROM ThirdTable END In the returning DataSet first column for all DataTables will have the TableName you have specified in the SP. You can identify the specific table using these names and assign an appropriate name to your DataTables.

        M 1 Reply Last reply
        0
        • S sharad48

          CREATE PROCEDURE MyProc AS BEGIN Select 'FirstTableName' AS TableName, Column1, Column2 FROM FirstTable Select 'SecondTableName' AS TableName, Column1, Column2 FROM SecondTable Select 'ThirdTableName' AS TableName, * FROM ThirdTable END In the returning DataSet first column for all DataTables will have the TableName you have specified in the SP. You can identify the specific table using these names and assign an appropriate name to your DataTables.

          M Offline
          M Offline
          Maxim Langman
          wrote on last edited by
          #4

          Good idea, but unfortunatelly doesn't work. It seems like the name of the table (select) never comes from Stored Procedure to the DataSet.Table. This is very sad, because any time the stored procedure is changed, the code has to be recompiled. So what I did, is an additional SELECT with the names of the tables in the order it goes in the SP. This way I know how many tables I get and the names and the order :-)

          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