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. How can i return the names of a stored procedures input parameters?

How can i return the names of a stored procedures input parameters?

Scheduled Pinned Locked Moved Database
csharpdatabasequestion
12 Posts 6 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
    Red_Wizard_Shot_The_Food
    wrote on last edited by
    #1

    Either using SQL or C#/ADO.NET is there a way for me to "probe" a stored procedure to return the names of its input parameters to my code? Thanks.

    M O L 3 Replies Last reply
    0
    • R Red_Wizard_Shot_The_Food

      Either using SQL or C#/ADO.NET is there a way for me to "probe" a stored procedure to return the names of its input parameters to my code? Thanks.

      M Offline
      M Offline
      Manas Bhardwaj
      wrote on last edited by
      #2

      Interseting!!! but I dont think its possible. :doh:

      O 1 Reply Last reply
      0
      • R Red_Wizard_Shot_The_Food

        Either using SQL or C#/ADO.NET is there a way for me to "probe" a stored procedure to return the names of its input parameters to my code? Thanks.

        O Offline
        O Offline
        originSH
        wrote on last edited by
        #3

        I assume your talking about sql server? If it's 2005 you want to use the System Views: http://www.microsoft.com/downloads/details.aspx?FamilyID=2ec9e842-40be-4321-9b56-92fd3860fb32&displaylang=en[^] If it's 2000 you want the system tables: http://www.microsoft.com/sql/prodinfo/previousversions/systables.mspx[^] Unfortunatly I dont have a link handy on how to use them, but they are pretty straight forward and will provide all you need :) Edit: just spotted this article. It looks old but relivent: http://www.devx.com/vb2themax/Tip/18282[^] -- modified at 6:16 Tuesday 26th June, 2007 Edit: I also forgot to tell you about DMO and SMO ;) SMO (Sql Management Objects) in 2005, is a set of objects you can use in .Net that retrive a lot of information about Sql Server and allows you to perform admin operations. They definatly allow you to list the stored procs and all the details about them. A little warning when used with a complex database the SMO's can require a fair bit of tweaking to perform well but it's well worth it if you need that much control. DMO is similar and used in 2000. I've never personally used DMO so you'dh ave to look into what it can achive.

        G 1 Reply Last reply
        0
        • M Manas Bhardwaj

          Interseting!!! but I dont think its possible. :doh:

          O Offline
          O Offline
          originSH
          wrote on last edited by
          #4

          In Sql Server theres atleast 2 different ways to achive this :cool:

          1 Reply Last reply
          0
          • O originSH

            I assume your talking about sql server? If it's 2005 you want to use the System Views: http://www.microsoft.com/downloads/details.aspx?FamilyID=2ec9e842-40be-4321-9b56-92fd3860fb32&displaylang=en[^] If it's 2000 you want the system tables: http://www.microsoft.com/sql/prodinfo/previousversions/systables.mspx[^] Unfortunatly I dont have a link handy on how to use them, but they are pretty straight forward and will provide all you need :) Edit: just spotted this article. It looks old but relivent: http://www.devx.com/vb2themax/Tip/18282[^] -- modified at 6:16 Tuesday 26th June, 2007 Edit: I also forgot to tell you about DMO and SMO ;) SMO (Sql Management Objects) in 2005, is a set of objects you can use in .Net that retrive a lot of information about Sql Server and allows you to perform admin operations. They definatly allow you to list the stored procs and all the details about them. A little warning when used with a complex database the SMO's can require a fair bit of tweaking to perform well but it's well worth it if you need that much control. DMO is similar and used in 2000. I've never personally used DMO so you'dh ave to look into what it can achive.

            G Offline
            G Offline
            Gamzun
            wrote on last edited by
            #5

            exec sp_sproc_columns MyStoredProcesure i guess is that what you're looking for!

            O 1 Reply Last reply
            0
            • G Gamzun

              exec sp_sproc_columns MyStoredProcesure i guess is that what you're looking for!

              O Offline
              O Offline
              originSH
              wrote on last edited by
              #6

              See ... we live and learn ;) Nice one :)

              G 1 Reply Last reply
              0
              • O originSH

                See ... we live and learn ;) Nice one :)

                G Offline
                G Offline
                Gamzun
                wrote on last edited by
                #7

                it woulde be better if you've said " We learn and live :D "

                O 1 Reply Last reply
                0
                • G Gamzun

                  it woulde be better if you've said " We learn and live :D "

                  O Offline
                  O Offline
                  originSH
                  wrote on last edited by
                  #8

                  Except the phrase is "We live and learn" :P We live and learn : (phrase used when sb has heard sthg new, unexpected, and surprising.) -- modified at 7:31 Tuesday 26th June, 2007

                  G 1 Reply Last reply
                  0
                  • O originSH

                    Except the phrase is "We live and learn" :P We live and learn : (phrase used when sb has heard sthg new, unexpected, and surprising.) -- modified at 7:31 Tuesday 26th June, 2007

                    G Offline
                    G Offline
                    Gamzun
                    wrote on last edited by
                    #9

                    oh thanks for the information mate :) so We Live and Learn! ;)

                    1 Reply Last reply
                    0
                    • R Red_Wizard_Shot_The_Food

                      Either using SQL or C#/ADO.NET is there a way for me to "probe" a stored procedure to return the names of its input parameters to my code? Thanks.

                      L Offline
                      L Offline
                      llamadillo
                      wrote on last edited by
                      #10

                      I'm not sure I can think of a valid business case as to why you'd want to do that. From a programmatic perspective, you'd still need the type and, depending upon the type, the size of the field. If you know both sides of the system, there are myriad better methods to perform what you're asking.

                      R 1 Reply Last reply
                      0
                      • L llamadillo

                        I'm not sure I can think of a valid business case as to why you'd want to do that. From a programmatic perspective, you'd still need the type and, depending upon the type, the size of the field. If you know both sides of the system, there are myriad better methods to perform what you're asking.

                        R Offline
                        R Offline
                        Red_Wizard_Shot_The_Food
                        wrote on last edited by
                        #11

                        Thanks guys I managed to do it in with .NET by using SqlCommandBuilder.DeriveParameters(MySqlCommand) It was used to create a generic method to loop through values from a DTO and place them into input parameters for a given Stored procedure on the mapper layer of our code. If I cache the results (for speed) it saves us lots of time rewriting very similar stuff inside each mapper to take the dto and asign its values to known paramaters in different procedures. So what i have is DataAdapter myMethod(string SProcName, DTOType inputParamsDTO) { DataAdapter da = new DataAdapter. [psudo] open connection to sql SqlCommandBuilder.DeriveParameters(SProcName) [psudo] loop [psudo] if SProcName.Param.Direction == input OR input/Output [psudo] if inputParamsDTO.Tables[0].Rows[0][i].Contains(SProcName.Param[i].ParamaterName) [psudo] SProcName.Param[i] = inputParamsDTO.Tables[0].Rows[0]["SProcName.Param[i].ParamaterName"] [psudo] end loop [psudo] close connection to sql [psudo] return da } So we pass it a SProc and a DTO (or dataset) and it gives us back a data adapter we can just calla Fill() on. But it needs to cache some where to stop excessive round trips

                        A 1 Reply Last reply
                        0
                        • R Red_Wizard_Shot_The_Food

                          Thanks guys I managed to do it in with .NET by using SqlCommandBuilder.DeriveParameters(MySqlCommand) It was used to create a generic method to loop through values from a DTO and place them into input parameters for a given Stored procedure on the mapper layer of our code. If I cache the results (for speed) it saves us lots of time rewriting very similar stuff inside each mapper to take the dto and asign its values to known paramaters in different procedures. So what i have is DataAdapter myMethod(string SProcName, DTOType inputParamsDTO) { DataAdapter da = new DataAdapter. [psudo] open connection to sql SqlCommandBuilder.DeriveParameters(SProcName) [psudo] loop [psudo] if SProcName.Param.Direction == input OR input/Output [psudo] if inputParamsDTO.Tables[0].Rows[0][i].Contains(SProcName.Param[i].ParamaterName) [psudo] SProcName.Param[i] = inputParamsDTO.Tables[0].Rows[0]["SProcName.Param[i].ParamaterName"] [psudo] end loop [psudo] close connection to sql [psudo] return da } So we pass it a SProc and a DTO (or dataset) and it gives us back a data adapter we can just calla Fill() on. But it needs to cache some where to stop excessive round trips

                          A Offline
                          A Offline
                          adambl
                          wrote on last edited by
                          #12

                          Microsft provide a class to do just this - SQLHelperParameterCache as part of its SQLHelper class as part of its Data Access Application Block. I don't have any links to hand, but google is your friend. Adam

                          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