title: VB.NET - Get a value from a field in a Access Database
body: <p>My game saves a score into the field of a database according to the user who has logged in. <strong>How do I retrieve the value of the score from the field and output it to a textbox?</strong> The user who is logged in is displayed in a textbox. The code that allows the user to log in is below. I need to retrieve the score value before <code>frmGame.Show()</code>.
  <strong>Thanks for help</strong></p>
  
  <pre><code>Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
  
      'Check if username or password fields are empty
      If txtUsername.Text = "" Or txtPassword.Text = "" Then
          MessageBox.Show("Please complete the required fields", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
      Else
          'Declare connection to database
          'OleDb = Object Linking and Embedding, Database
          Dim connDB As New System.Data.OleDb.OleDbConnection()
          'Location of Access Database
          connDB.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Year 12\Information Technology\Programming\WindowsApplication2\userDatabase.accdb"
  
          Try
              'Holds the username and password 
              Dim sql As String = "SELECT * FROM tbl_user WHERE User='" &amp; txtUsername.Text &amp; "' AND Pass= '" &amp; txtPassword.Text &amp; "'"
              Dim sqlCom As New System.Data.OleDb.OleDbCommand(sql)
  
              'Open database connection
              sqlCom.Connection = connDB
              connDB.Open()
              Dim sqlRead As System.Data.OleDb.OleDbDataReader = sqlCom.ExecuteReader()
  
              'If username and password validated then display game form
              If sqlRead.Read() Then
                  Me.Hide()
                  frmGame.Show()
              Else
                  'Authentication failure message 
                  MessageBox.Show("Incorrect username or password", "Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                  txtUsername.Text = ""
                  txtPassword.Text = ""
                  txtUsername.Focus()
              End If
  
              'Database connection failure message 
          Catch ex As Exception
              MessageBox.Show("Connection to User Database failed" &amp; ex.Message, "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
          End Try
  
      End If
  
  End Sub
  </code></pre>