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?
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;
Take a look at the SqlParameterCollection and SqlParameter class definitions for more information.
I am not sure if you can do it in the ADO.NET environment directly, somehow - but you could always query the "sys" system views to get that information:
select * from sys.parameters
where object_id in
(select object_id from sys.procedures where name = 'YourSProc')
Marc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With