title: Convert dbnull to string. Record dbnull.value in database instead of Nothing
body: <p>I have an insertRecord function in vb.net that uses a parameter query. If there is no error date given, I need to insert dbnull.value into the db instead of ""(Nothing).</p>
  
  <pre><code>Dim strErrorDate2 As DateTime = Request.Form("dateOfErrorDatePicker2").ToString
  
  .Add(New SqlParameter("@ErrorDate2", If(strErrorDate2 &lt;&gt; Nothing, strErrorDate2.Date, DBNull.Value)))
  </code></pre>
  
  <p>I keep getting conversion errors on dbnull to string. Originally it had it's own if/else block where I initialized the variable, but I couldn't figure out how to convert it correctly. I tried the inline if, but I still need to do a conversion or try something else.</p>
  
  <p>Any ideas? The problem is that when I insert an empty string or DateTime into the database it records as a min possible date such as 1/1/1900.</p>
  
  <p>EDIT: "Cannot infer a common type, 'object' assumed." That's the error I'm currently getting.</p>