title: How do I test for DBNull so as not to crash with "Column .... does not belong to table row"?
body: <p>I am reading 2 tables in T-SQL like so:</p>
  
  <p><code>Select r.UID,c.Forename,c.Surname,c.DOB From c LEFT OUTER JOIN r on........</code></p>
  
  <p>Then in VB.NET I loop through the dataset like so:</p>
  
  <pre><code>For Each drR In dsR.Tables(0).Rows......Next
  </code></pre>
  
  <p>However when I test like so: </p>
  
  <pre><code>If Convert.IsDBNull(drR("r.UID")) Then 
  </code></pre>
  
  <p>Or </p>
  
  <pre><code>String.IsNullOrEmpty(drR("r.UID"))
   Convert.IsDBNull(r.UID))
  </code></pre>
  
  <p>I crash with </p>
  
  <blockquote>
    <p>Column 'UID' does not belong to table
    row</p>
  </blockquote>
  
  <p>when the second table r has no record.</p>
  
  <p>I did try both r.UID and UID. </p>
  
  <p>To recoup: All is fine when I have a record in the second table, but what must I do when I do not?  How do I test for DBNull so as not to crash with "Column .... does not belong to table row"?</p>
  
  <p>P.S. Regardng the 2 answers below: I have to test for UID so as to know whether there is a record in the 2nd table or not.</p>