title: Cast a sqlparameter into a DBNULL value if it's null
body: <p>I have a query that update a certain table inside my database in which I assign a parameter to it, this latter take value of a textbox.text if the value isn't null it works just fine, if it is, I get this error message "When converting a string to DateTime, parse the string to take the date before putting each variable into the DateTime object".</p>
  
  <p>My question is, what type of casting should I use to avoid the use of If statement?</p>
  
  <pre><code>SqlCommand loadbonus = new SqlCommand()
  loadbonus.Connection = conn;
  loadbonus.CommandText = "UPDATE Client SET [Restant Bonus]=[Restant Bonus]-(SELECT SUM([Prix Total]) FROM Comptoir WHERE [N° Comptoir]='" + tabcontrol.SelectedIndex + "'),[Total Consommé]=[Total Consommé]+(SELECT SUM([Prix Total]) FROM Comptoir WHERE [N° Comptoir]='" + tabcontrol.SelectedIndex + "') OUTPUT INSERTED.[Restant Bonus] WHERE [Code Client]=@CodeClient";          
  loadbonus.Parameters.Add("@CodeClient", SqlDbType.Int).Value = Convert.ToInt32(clientcodecomptoire.Text);
  </code></pre>
  
  <p>Actual error message :</p>
  
  <p>"When converting a string to DateTime, parse the string to take the date before putting each variable into the DateTime object"</p>
  
  <p>I have tried the following casting and it didn't work:</p>
  
  <pre><code>loadbonus.Parameters.Add("@CodeClient", SqlDbType.Int).Value = Convert.ToInt32(clientcodecomptoire.Text)??DBNull.Value;
  </code></pre>