Given a Stored procedure, I want to extract the parameter from it.
How can I do this in .net?
You can run the following SQL query in SQL Server 2005. You can of course call the same query using the SqlCommand
class.
SELECT
p.name,
p.object_id,
pm.parameter_id,
pm.name AS parameter_name,
pm.system_type_id AS parameter_system_type_id,
pm.max_length AS parameter_max_length,
t.name AS type_name
FROM sys.procedures p
JOIN sys.parameters pm ON p.object_id = pm.object_id
JOIN sys.types t ON pm.system_type_id = t.system_type_id
WHERE p.name = 'sprocName'
Of course, the procedures
, parameters
and types
system views contain other interesting stored procedure and parameter information as well. This query is just a selection.
You should use the SqlCommandBuilder.DeriveParameter, which is Shared (VB.NET) or Static (C#) to which you pass the SqlCommand: DeriveParameter on MSDN . You just have to create a SqlCommand, setting the name of the stored procedure, call this method and look at the SqlCommand.Parameters property.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.