Is it possible to get the number of parameters being passed to a method in run time, and if so how?
For instance, if if would be possible, I could have a database interaction method as follows,
public void AddSomethingToDatabase(string parameter1, string parameter2)
{
...
foreach(param in parameters)
{
sp.AddParameter(GetName(param),param));
}
conn.Execute(...);
}
I am attempting to not have to add/change a line in code each time my stored procedure parameters change, instead only changing the method signature with the correct stored procedure parameters. In this case, parameter1 and parameter2 would be the actual names of the parameters in the stored procedure. Any ideas?
Can you pass the parameters as a collection? This way it is unlimited and easy to use.
This is how I do it for my own projects
EDIT : I’d like to clarify more how I used this method in my own programs.
I specify the database procedure parameters in the method itself, and pass the parameters like you do. I do realise there is a better way, like using DTO’s