title: Validating Username And Password from MySQL
body: <p>I'm looking for a code that validates the username and password in VB.</p>
  
  <pre><code>Private Sub LoginBtn_Click(sender As Object, e As EventArgs) Handles LoginBtn.Click
      Try
          con.Open()
          com = New MySqlCommand("SELECT id FROM accounts WHERE uname='" &amp; txtuname.Text &amp; "'", con)
          reader = com.ExecuteReader
          If reader.HasRows = True Then
              com = New MySqlCommand("SELECT id FROM accounts WHERE pword = '" &amp; txtpword.Text &amp; "' AND uname='" &amp; txtuname.Text &amp; "'", con)
              If reader.HasRows = True Then
                  Form3.Show()
              Else
                  MsgBox("Invalid Password")
                  txtpword.Focus()
              End If
  
          ElseIf String.IsNullOrEmpty(txtuname.Text) Then
              MsgBox("Invalid Username")
              txtuname.Focus()
          Else
              MsgBox("New User Detected. Input Password")
              Form2.Show()
          End If
  
          reader.Close()
          con.Close()
  
      Catch ex As Exception
          If Not con.State = ConnectionState.Closed Then
              con.Close()
          End If
          MsgBox(ex.ToString)
      End Try
  
  End Sub
  </code></pre>
  
  <p>The conditions goes like this:</p>
  
  <ol>
  <li>If the username is not detected from the dbase, it'll lead to a registration form(which is form2)</li>
  <li>If the username was detected but the password is wrong or empty, a msgbox will pop up</li>
  <li>If the username and password is both correct, it'll lead to form 3.</li>
  </ol>
  
  <p>My problem is condition #2. Even though the data in the pword txtbox is wrong, it still keeps leading to form 3 instead of showing a msgbox.</p>