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. Retreive Data from sql server along with headers or column name

Retreive Data from sql server along with headers or column name

Scheduled Pinned Locked Moved Database
helpcsharpcssdatabase
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.
  • A Offline
    A Offline
    ashu2001
    wrote on last edited by
    #1

    hello everyone, i am using vb.net2003 ( for a windows application ) along with sql server 2005 i need to display data of a sql procedure whose columns are being generated dynamically. The problem arise when i want to give header of flexgrid as i am not able to find out how many sql column will be retrieved/generated after the execution of the procedure and what their headers will be (i.e column name as i am using pivot to generate column from a temp table in which n number of distinct values can appear as rows, which will be used in pivot for which n number of column fields will be generated accordingly ). As i have to give header of grid and number of column is unknown , i am struck here...Plz help

    ashish sharma

    G L C 3 Replies Last reply
    0
    • A ashu2001

      hello everyone, i am using vb.net2003 ( for a windows application ) along with sql server 2005 i need to display data of a sql procedure whose columns are being generated dynamically. The problem arise when i want to give header of flexgrid as i am not able to find out how many sql column will be retrieved/generated after the execution of the procedure and what their headers will be (i.e column name as i am using pivot to generate column from a temp table in which n number of distinct values can appear as rows, which will be used in pivot for which n number of column fields will be generated accordingly ). As i have to give header of grid and number of column is unknown , i am struck here...Plz help

      ashish sharma

      G Offline
      G Offline
      GuyThiebaut
      wrote on last edited by
      #2

      The short answer is if the columns are being generated dynamically and you don't know what columns will be there, guess what neither will .Net be able to work this out! However if you return the results of the stored procedure into a Datatable you will be able to iterate through the Columns collection -> clickety[^]

      “That which can be asserted without evidence, can be dismissed without evidence.”

      ― Christopher Hitchens

      J 1 Reply Last reply
      0
      • A ashu2001

        hello everyone, i am using vb.net2003 ( for a windows application ) along with sql server 2005 i need to display data of a sql procedure whose columns are being generated dynamically. The problem arise when i want to give header of flexgrid as i am not able to find out how many sql column will be retrieved/generated after the execution of the procedure and what their headers will be (i.e column name as i am using pivot to generate column from a temp table in which n number of distinct values can appear as rows, which will be used in pivot for which n number of column fields will be generated accordingly ). As i have to give header of grid and number of column is unknown , i am struck here...Plz help

        ashish sharma

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

        Please don't crosspost, and don't repeat a question without additional information. The FlexGrid is part of Visual Studio 6. It should die along with VB6. In VB.NET, one would use the DataGridView. Once you fetch the data, you can get the schema information from the datareader.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        1 Reply Last reply
        0
        • A ashu2001

          hello everyone, i am using vb.net2003 ( for a windows application ) along with sql server 2005 i need to display data of a sql procedure whose columns are being generated dynamically. The problem arise when i want to give header of flexgrid as i am not able to find out how many sql column will be retrieved/generated after the execution of the procedure and what their headers will be (i.e column name as i am using pivot to generate column from a temp table in which n number of distinct values can appear as rows, which will be used in pivot for which n number of column fields will be generated accordingly ). As i have to give header of grid and number of column is unknown , i am struck here...Plz help

          ashish sharma

          C Offline
          C Offline
          Corporal Agarn
          wrote on last edited by
          #4

          If you have a temporary table you can use

          select * from tempdb.sys.columns where object_id = object_id('tempdb..#yourtable');

          you can create a header. From here there are a couple of ways to handle the data and not being very good at VB.NET I will let you handle that.

          1 Reply Last reply
          0
          • G GuyThiebaut

            The short answer is if the columns are being generated dynamically and you don't know what columns will be there, guess what neither will .Net be able to work this out! However if you return the results of the stored procedure into a Datatable you will be able to iterate through the Columns collection -> clickety[^]

            “That which can be asserted without evidence, can be dismissed without evidence.”

            ― Christopher Hitchens

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            GuyThiebaut wrote:

            , guess what neither will .Net be able to work this out!

            Most modern databases provide a way to query for most or even all of the meta data associated with the database. SQL Server provides a way to query for table column names.

            G 1 Reply Last reply
            0
            • J jschell

              GuyThiebaut wrote:

              , guess what neither will .Net be able to work this out!

              Most modern databases provide a way to query for most or even all of the meta data associated with the database. SQL Server provides a way to query for table column names.

              G Offline
              G Offline
              GuyThiebaut
              wrote on last edited by
              #6

              The OP says: "i need to display data of a sql procedure whose columns are being generated dynamically" Because the columns are being generated "dynamically" there is no way to retrieve the meta data relating to the SP before the SP is run. Also meta data relating to SPs pretty much only extends to getting the input parameters.

              “That which can be asserted without evidence, can be dismissed without evidence.”

              ― Christopher Hitchens

              J 1 Reply Last reply
              0
              • G GuyThiebaut

                The OP says: "i need to display data of a sql procedure whose columns are being generated dynamically" Because the columns are being generated "dynamically" there is no way to retrieve the meta data relating to the SP before the SP is run. Also meta data relating to SPs pretty much only extends to getting the input parameters.

                “That which can be asserted without evidence, can be dismissed without evidence.”

                ― Christopher Hitchens

                J Offline
                J Offline
                jschell
                wrote on last edited by
                #7

                GuyThiebaut wrote:

                "i need to display data of a sql procedure whose columns are being generated dynamically"

                Misread that. I thought they were using tables which had been created by some runtime process.

                G 1 Reply Last reply
                0
                • J jschell

                  GuyThiebaut wrote:

                  "i need to display data of a sql procedure whose columns are being generated dynamically"

                  Misread that. I thought they were using tables which had been created by some runtime process.

                  G Offline
                  G Offline
                  GuyThiebaut
                  wrote on last edited by
                  #8

                  You've got a good point there - as there is some ambiguity in the word dynamic. I just answered the question based on how I dynamically generate columns in SPs - so yes,. if the columns were generated through the .net code or based on some meta data in a table it would be possible to know information regarding the columns before they were generated.

                  “That which can be asserted without evidence, can be dismissed without evidence.”

                  ― Christopher Hitchens

                  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