title: How can you determine if I certain parameter exists when adding values?
body: <p>I haven't worked with SQL in a really long time but a new project is requiring I get my hands dirty with it. I'm building a SELECT statement from a few textboxes on my page and started to write the code to add parameter values when it occurred to me that not every parameter might get used.</p>
  
  <p>For example:</p>
  
  <pre><code>    string parameterizedQuery = " SELECT * FROM dbo.Account WHERE ";
      if (!string.IsNullOrEmpty(txtAccountNumber.Text.Trim()))
          parameterizedQuery += " AccountNumber = @AccountNumber";
  
      //5 more instances of similar query building for other fields
  
      SqlCommand cmd = new SqlCommand(parameterizedQuery, sqlconn);
      cmd.Parameters.AddWithValue("@AccountNumber", txtAccountNumber.Text.Trim());
  </code></pre>
  
  <p>But it's possible that <code>@AccountNumber</code> won't make its way into the query if the user isn't searching with that field. Is there a better way to accomplish this? I know that's a really subjective question but I feel like I cannot being doing this correctly or efficiently.</p>