title: Conditionally null values inside of a list of SqlParameters
body: <p>We have a block of code that creates a list of sqlParameters and then passes them to the stored procedure.  A requirement came in to conditionally null a few of the values based on whether or not the input textbox is blank.</p>
  
  <p>Base code:</p>
  
  <pre><code>var SqlParams = new List&lt;SqlParameter&gt; {
      new SqlParameter("@SomeFloat", SqlDbType.FLoat) {Value = f},
      ....
  }
  </code></pre>
  
  <p>I tried a few variations on something, but it didn't work and VS gives an error about no implicit conversion between float and null.</p>
  
  <pre><code>new SqlParameter("@SomeFloat", SqlDbType.Float) {Value = (!string.IsNullOrEmpty(tb.Text) ? double.Parse(tb.Text) : DBNull.Value)},
  </code></pre>
  
  <p>Is there a way to do this maintaining the list of parameters so that we dont have to rewrite the whole module?</p>
  
  <p>Thanks</p>