title: Check if datareader is null or has no rows? ASP.NET
body: <p>So I took over this project and one page is throwing a lot of errors. I would need to refactor the whole thing but as always time is an issue.</p>
  
  <p>In one case the code check's whether a datareader has any rows and if not go to an error page. However as the code is now the datareader can be null (didn't successfully connect to db) and in those cases I can't use</p>
  
  <pre><code>if (!dr.HasRows)
  //
  </code></pre>
  
  <p>becasuse it obviously gives me 'nullreferenceexception was unhandled by code'. I tried with !dr.Read but same thing.</p>
  
  <p>A part of the code is something like</p>
  
  <pre><code>SqlDataReader dr = null;
  try
  {
  //connect to db etc
  dr = DbHelper.GetReader("sp_GetCustomer", param);
  }
  catch
  {
  //show an error message
  }
  
  // and then:
  if (!dr.HasRows)
  {
  
  }
  </code></pre>
  
  <p>Any suggestions?</p>
  
  <p>Thanks in advance.</p>