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?
4 Answers
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.