How can I retrieve a list of parameters from a stored procedure in SQL Server

后端 未结 8 1115
慢半拍i
慢半拍i 2020-11-28 12:14

Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters that belong to a stored procedure on a SQL Server before I actually execute it?

I

8条回答
  •  再見小時候
    2020-11-28 12:35

    All of these ADO.NET solutions are are asking the code library to query the database's metadata on your behalf. If you are going to take that performance hit anyhow, maybe you should just write some helper functions that call

    Select count(*) from information_schema.parameters 
    where ...(proc name =.. param name=...) (pseudo-code)
    

    Or maybe even generate your parameters based on the param list you get back. This technique will work with multiple versions of MS SQL and sometimes other ANSI SQL databases.

提交回复
热议问题