title: Option Strict and Nulls
body: <p>I do not want empty strings in the database. When a field is null, I want it to be null.
  I am trying to replace</p>
  
  <pre><code>If strStreet = "" Then
              cmd.Parameters("@Street").Value = DBNull.Value
          Else
              cmd.Parameters("@Street").Value = strStreet
          End If
  </code></pre>
  
  <p>with the VB If Operator as follows</p>
  
  <pre><code> cmd.Parameters("@Street").Value = If(strStreet = "", DBNull.Value, strStreet)
  </code></pre>
  
  <p>I get the following message from the red squiggly under everything to the right of the first = sign.
  "Cannot infer a common type, and Option Strict On does not allow 'Object' to be assumed."
  OK, so I do a little cast</p>
  
  <pre><code>cmd.Parameters("@Street").Value = If(strStreet = "", CObj(DBNull.Value), strStreet)
  </code></pre>
  
  <p>The red squiggly disappears and a green squiggly appears under CObj saying redundant Cast.
  Should I 
  A. Turn off Option Strict
  B. Ignore the green squiggly
  C. Go back to my If...Else...End If
  or something else??
  BTW it works great in the other direction when I am preparing a string for the Text property of some control.</p>
  
  <pre><code>strStreet = If(reader.GetValue(2) IsNot DBNull.Value, reader.GetString(2), "")
  </code></pre>
  
  <p>I have read several question and answers here that are circling my problem but I can't quite get it.
  Thank you for your kind attention.</p>