One function for multiple stored procedures C#
<p>I have a function that executes stored procedures. The thing is, I wish to use this one function for multiple stored procedures that take different arguments. </p>

<p>Of course, if I do so, I will get an error saying that </p>

<blockquote>
  <p>Procedure or function  has too many arguments specified</p>
</blockquote>

<p>What I want to do is to create the function such that when it executes a stored procedure, that stored procedure only takes the parameters that it needs and ignore the others. Is this possible?</p>

<p>Here is what I have so far:</p>

<pre><code>try
{
    using (SqlConnection con = new SqlConnection(consr))
    {
        SqlCommand cmd = new SqlCommand();
        SqlDataReader reader;
        cmd.CommandText = stp;
        cmd.Parameters.Add(new SqlParameter("@proc1", cmb1.SelectedItem.ToString()));
        cmd.Parameters.Add(new SqlParameter("@proc2", cmb2.SelectedItem.ToString()));
        cmd.Parameters.Add(new SqlParameter("@proc3", cmb3.SelectedItem.ToString()));
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Connection = con;
        con.Open();

        reader = cmd.ExecuteReader();

        con.Close();
    }
}
catch (SqlException exp)
{
    throw new InvalidOperationException(exp.Message);
}
</code></pre>

<p>Here are two of the procedures:</p>

<pre><code>ALTER PROCEDURE [dbo].[test1]
@proc1 varchar(20)

AS 

Begin

select * from tab where name=@proc1 

END
</code></pre>

<p>and</p>

<pre><code>ALTER PROCEDURE [dbo].[test1]
@proc2 varchar(20)

AS 

Begin

select * from tab where name=@proc2

END
</code></pre>

<p>I want to use the same function to execute both</p>