我如何可以检索的参数列表,在SQL Server存储过程 [英] How can I retrieve a list of parameters from a stored procedure in SQL Server
问题描述
使用C#和System.Data.SqlClient,有没有办法来获取属于一个存储过程在SQL Server的参数列表之前,我实际执行呢?
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 have an a "multi-environment" scenario where there are multiple versions of the same database schema. Examples of environments might be "Development", "Staging", & "Production". "Development" is going to have one version of the stored procedure and "Staging" is going to have another.
我想要做的就是验证一个参数是要传递给它的值并调用存储过程之前赶到那里。避免了SQLEXCEPTION而不是抓住这是一个加我。
All I want to do is validate that a parameter is going to be there before passing it a value and calling the stored procedure. Avoiding that SqlException rather than having to catch it is a plus for me.
约书亚
推荐答案
您可以使用SqlCommandBuilder.DeriveParameters()(请参阅<一href="https://web.archive.org/web/20110304121600/http://www.davidhayden.com/blog/dave/archive/2006/11/01/SqlCommandBuilderDeriveParameters.aspx"相对=nofollow> SqlCommandBuilder.DeriveParameters - 获取参数信息存储过程 - ADO.NET教程)或有的这样这是不一样优雅。
You can use SqlCommandBuilder.DeriveParameters() (see SqlCommandBuilder.DeriveParameters - Get Parameter Information for a Stored Procedure - ADO.NET Tutorials) or there's this way which isn't as elegant.
这篇关于我如何可以检索的参数列表,在SQL Server存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!