How can I retrieve a list of parameters from a stored procedure in SQL Server(如何从 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()(见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 中的存储过程中检索参数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 SQL Server 中的存储过程中检索参数列表


基础教程推荐
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01