title: Invalid attempt to access a field before calling Read() vb.net
body: <p>I Got this error not because of code error but because of there is no data in my table</p>
  
  <p>How to check if there is no data and return in variable as 0</p>
  
  <p>here is my code
  i am trying to get counter number, but it's error when no records</p>
  
  <pre><code>Public Function GetCount()
     Dim count As Integer
     Dim cmd As New MySqlCommand
     Dim reader As MySqlDataReader = Nothing
     Conn.OpenConn()
     Dim sqlstr As String
     sqlstr = "SELECT counter FROM st_sales ORDER BY salesid DESC LIMIT 1"
     Try
      'CREATE COMMAND
       cmd = New MySqlCommand(sqlstr, Conn.Conn)
  
       reader = cmd.ExecuteReader()
       If reader.Read() Then
          count = reader.GetInt32(0) + 1
       Else
          MsgBox("Error")
       End If
      Finally
         reader.Close()
         Conn.CloseConn()
      End Try
      Return count
  End Function
  </code></pre>
  
  <p>Thanks for any healp</p>