title: Nullable Object must have a value #2
body: <p>I'm trying to reuse the same code I've always used but now it is encountering an error.</p>
  
  <p>I'm looping through various user tables, and in there I do this:</p>
  
  <pre><code>DateTime dcdt = (DateTime)u.DateCreated;
  DateTime lldt = (DateTime)u.LastLogon;
  userRow["DateCreated"] = dcdt.ToShortDateString();
  </code></pre>
  
  <p>inside the loop. I get the error:</p>
  
  <pre><code>System.InvalidOperationException: Nullable object must have a value.
  </code></pre>
  
  <p><strong>The error highlights "lldt" line</strong>, instead of "dcdt" which comes first. That is strange in and of itself. Both these fields in the database "allow nulls" is checked. And they both could be null or neither might be null.</p>
  
  <p>The two values are both listed as DateTime? types through intellisense.</p>
  
  <p>I don't understand why ASP.NET refuses to allow me to output blank for null dates. If it is empty/null, then logic would suggest that ASP.NET should just print nothing.</p>
  
  <p>How else am I suppose to output null dates? I tried adding if statements to prevent trying to cast null DateTimes, but it doesn't help, it makes no sense.</p>