title: Dynamic WHERE clauses in a SqlDataSource
body: <p>I'm using a SqlDataSource in a very simple application.  I'm allowing the user to set several search parameters for the SDS's select command via TextBoxes, one TextBox per parameter (think txtFirstName, txtLastName, etc).  I'm planning on using a button click event handler to set the SqlDataSource's SelectCommand property which by default will return all records (for my purposes here).  I want to refine this select command to possibly add one or more WHERE clauses depending on if the user enters search criteria in any of my TextBoxes.</p>
  
  <p>Example in case I'm not being clear:</p>
  
  <p>By default, my SqlDataSource's SelectCommand property will be something like this:</p>
  
  <pre><code>SELECT * FROM MyTable
  </code></pre>
  
  <p>If the user enters "Bob" in txtFirstName, I want to SelectCommand property to look like this:</p>
  
  <pre><code>SELECT * FROM MyTable WHERE [FirstName]='Bob'
  </code></pre>
  
  <p>If the user enters "Jones" in txtLastName, I want to SelectCommand property to look like this:</p>
  
  <pre><code>SELECT * FROM MyTable WHERE [FirstName]='Bob' AND [LastName]='Jones'
  </code></pre>
  
  <p><strong>My question:</strong><br>
  Is there a way to dynamically create these WHERE clauses without me having to test for empty TextBoxes and constructing a WHERE clause by hand?</p>
  
  <p>My little application only has three parameters so brute forcing my way through this wouldn't be painful, but I've wondered if there was an easier way to do this plus it's possible I'll need to add more parameters in the future.  Plus I may want to add wildcard searching.</p>