title: Is there a way to check if a parameter is in stored procedure?
body: <p>I'm writing a general purpose function for feeding query string straight into a sproc. The algorithm is fairly basic - loop through query keys, use them as parameter names while the value are used as parameter values. So it looks like something like this:</p>
  
  <pre><code>ArrayList pars = new ArrayList();
  SqlParameter p;
  int tryInt;
  for (int i = 0; i &lt; req.QueryString.Count; i++) 
  {
      key = req.QueryString.AllKeys[i];
  
      if (int.TryParse(req[key], out tryInt)) 
      {
          p = new SqlParameter("@" + key, SqlDbType.Int);
          p.Value = tryInt;
          pars.Add(p);
      }
  }
  </code></pre>
  
  <p>This works fine so far, except that of course all query keys must match the parameters for the sproc, if they don't I get an SQL exception saying something like</p>
  
  <pre><code>@someParameter is not a parameter for procedure some_sproc
  </code></pre>
  
  <p>But I need to be able to pass in variables in the query string that won't be passed into the sproc, so I need a way to "ignore" them.</p>
  
  <p>Is there a way to test whether a given stored procedure expects a certain parameter? So that I can do something along these lines</p>
  
  <pre><code>if (paramExists("@" + key, "some_sproc") &amp;&amp; int.TryParse(req[key], out tryInt)) 
  {
      p = new SqlParameter("@" + key, SqlDbType.Int);
      p.Value = tryInt;
      pars.Add(p);
  }
  </code></pre>