title: Convert empty string into Null to save Null Values into SQL Server database
body: <p>I just read out very nice answers to save null into database column using </p>
  
  <pre><code>string.IsNullOrWhiteSpace(textbox.tex) ? (object)textbox.text: DBNull.Value;
  </code></pre>
  
  <p>or using </p>
  
  <pre><code>cmd.Parameters.AddWithValue("foo",
      foo == null ? (object)DBNull.Value : (object)foo);
  </code></pre>
  
  <p>and I tried with others too but it's not working for me as I am not very expert of C# language but I must want to save null into my SQL Server database column.</p>
  
  <p>Here is my code which I tried to save null value but it sends empty string which is not my requirement.</p>
  
  <pre><code>oCourseRegistrationPaypal.UserTheoryTrainingDate4 = Convert.ToString(DBNull.Value);
  </code></pre>
  
  <p>So when I write </p>
  
  <pre><code>oCourseRegistrationPaypal.UserTheoryTrainingDate4 = null; 
  </code></pre>
  
  <p>it gives me error that my procedure wants parameter which was not supplied but I know that I have supplied null to it.</p>
  
  <p>When I write </p>
  
  <pre><code>oCourseRegistrationPaypal.UserTheoryTrainingDate4=Convert.ToString(DBNull.Value);
  </code></pre>
  
  <p>it saves the empty string in my database column but I need a <code>null</code> value there.</p>
  
  <p>When I manually save null values in stored procedure it accepts null and save null but why it is not accepting </p>
  
  <pre><code>oCourseRegistrationPaypal.UserTheoryTrainingDate4 = null;
  </code></pre>
  
  <p>from my C# code?</p>
  
  <p>Is there a better way to do this? </p>