title: How to avoid IndexOutOfRangeException indexing DataReader columns?
body: <p>I am having a little trouble with an 'IndexOutOfRangeException'. I think it is because when the code tries to get the DateModified col from the database it sometimes contains NULLS (the users haven't always updated the page since they created it).</p>
  
  <p>Here is my code;</p>
  
  <pre><code>s = ("select datemodified, maintainedby, email, hitcount from updates where id =   @footid")
  Dim x As New SqlCommand(s, c)
  x.Parameters.Add("@footid", SqlDbType.Int)
  x.Parameters("@footid").Value = footid
  c.Open()
  Dim r As SqlDataReader = x.ExecuteReader
  While r.Read
      If r.HasRows Then
          datemodified = (r("DateModified"))
          maintainedby = (r("maintainedby"))
          email = (r("email"))
          hitcount = (r("hitcount"))
      End If
  End While
  c.Close()
  </code></pre>
  
  <p>I thought (after a bit of msdn) that adding;</p>
  
  <pre><code>If r.HasRows Then 
  
  End If 
  </code></pre>
  
  <p>Would solve the problem, but so far after adding I am still getting the same old IndexOutOfRangeException</p>
  
  <p>(ps, I have tried datemodified as string / datetime)</p>