从SqlDataSource的给定存储过程名称获取参数列表 [英] Get a Parameter List from an SQLDataSource given Stored Procedure Name
问题描述
有没有一种理智的方式来获得预期的参数列表,从给定的分配给其SelectCommand属性的存储过程的名称的SqlDataSource的?
Is there a sane way to get a list of expected parameters from an SqlDataSource given the name of the stored procedure assigned to its SelectCommand property?
推荐答案
您可以使用SqlCommandBuilder.DeriveParameters方法返回与存储过程相关的参数信息。遍历集合将允许您确定参数名称,数据类型,方向等。
You can use the SqlCommandBuilder.DeriveParameters method to return information on the parameters associated with a stored procedure. Iterating over the collection will allow you to determine the parameter name, data type, direction, etc.
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection("myConnectionString");
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "myStoredProcName";
cmd.Connection = conn;
conn.Open();
SqlCommandBuilder.DeriveParameters(cmd);
conn.Close();
SqlParameterCollection collection = cmd.Parameters;
看看的 SqlParameterCollection 和的SqlParameter 类定义的详细信息。
Take a look at the SqlParameterCollection and SqlParameter class definitions for more information.
这篇关于从SqlDataSource的给定存储过程名称获取参数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!