title: MysqlException was unhandled DataReader with this connection must be closed vb.net
body: <p>I have encountered this problem:</p>
  
  <p><strong>ERROR:</strong> There is already an open DataReader associated with this Connection which must be closed first.</p>
  
  <p>Please have a look on my code:</p>
  
  <pre><code> Dim sqlQuery As String = "SELECT * FROM users"
      Dim myAdapter As New MySqlDataAdapter
  
      If txtUsername.Text = String.Empty And txtPassword.Text = String.Empty Then
          MsgBox("Enter username and password", MsgBoxStyle.Exclamation, "Tea Sparkle POS")
      Else
          Dim sqlquerry = "Select * From users where username = '" + txtUsername.Text + "' And password= '" + txtPassword.Text + "'"
          Dim myCommand As New MySqlCommand()
          myCommand.Connection = SQLConnection
          myCommand.CommandText = sqlquerry
          'Starting The Query
          myAdapter.SelectCommand = myCommand
          Dim mydata As MySqlDataReader
          mydata = myCommand.ExecuteReader()
          'To check the Username and password and to validate the login a
          If mydata.HasRows = 0 Then
              MsgBox("Invalid Login")
              txtPassword.Clear()
              txtUsername.Clear()
          Else
              Dim authorityid = 0
              While mydata.Read()
                  authorityid = mydata.GetInt32("authorityid")
              End While
              MsgBox("Welcome " + txtUsername.Text + "!")
              If authorityid = 1 Then
                  MainForm.Show()
              Else
                  MainForm.Show()
              End If
              Me.Hide()
          End If
      End If
  
  
      Private Sub Login_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  
      SQLConnection.ConnectionString = ServerString
  
      Try
          If SQLConnection.State = ConnectionState.Closed Then
              SQLConnection.Open()
          Else
              SQLConnection.Close()
          End If
      Catch ex As Exception
          MsgBox(ex.ToString)
      End Try
  
  End Sub
  </code></pre>
  
  <p>This error is in this line:</p>
  
  <pre><code> mydata = myCommand.ExecuteReader()
  </code></pre>
  
  <p>What's wrong with this? Any help is truly appreciated.</p>