title: cmd.Parameters.AddWithValue("@param1",param1 ?? DbNull.Value)
body: <p>I have int? type value which can be either null or have some value. I want to execute a insert statement using parametrized query to insert accordingly.</p>
  
  <pre><code>int? val1=null; 
  SqlCeCommand cmd;
  string insert = "insert into table(col1)values(@col_1)";
  cmd = new SqlCeCommand();
  cmd.CommandText = insert;
  cmd.Parameters.AddWithValue("@col_1", val1 ?? Convert.ToInt32(DBNull.Value)));
  cmd.Connection = cn1;
  cn1.Open();
  cmd.ExecuteNonQuery();
  cn1.Close();
  </code></pre>
  
  <p>This code throws format exception error. I even tried</p>
  
  <pre><code>cmd.Parameters.AddWithValue("@col_1", (!val1.HasValue) ? val1 : Convert.ToInt32(DBNull.Value));
  </code></pre>
  
  <p>How shld it b done?</p>