title: System.nullreferenceexception: object reference not set to an instance of an object in vb
body: <p>I get this error when I run my program. <code>System.nullreferenceexception: object reference not set to an instance of an object</code>. It appears the error points to the part where am querying the database. This is the code </p>
  
  <pre><code> cmdx.Connection = cnn
   cmdx.CommandText = "SELECT farmer_centre from farmer WHERE farmer_num ='" &amp; fnumDField.Text.Trim &amp; "'"
  
          myDatad = cmdx.ExecuteReader
  
          While myDatad.Read()
              Dim dbCentre As String = myDatad(0).ToString
          End While
  </code></pre>
  
  <p>I declared dbCentre globally as 
      <code>Dim dbCentre As String</code>. 
  What should I do here on? Am using vb and the database is access</p>