title: Vb, SQL statement error. Can't figure it out
body: <p>I'm trying to build my first program and I've run into a few problems with SQL. </p>
  
  <p>I have a database with customers and employees (among other things) and I'm trying to set up a basic login screen. Users log in with their EmployeeID (primary key)</p>
  
  <p>This part deals with logging in for the first time.</p>
  
  <p>It checks the database for a user with that ID and grabs the password. If the password is not empty / null, it shows a message box and stops there. </p>
  
  <p>If the password is empty/null it is meant to confirm and then update the new password.</p>
  
  <p>This is where my understanding ends. Debugging shows the error is definitely in the SQL update, but I can't see any errors...</p>
  
  <p>Help?</p>
  
  <p>Thanks.</p>
  
  <p>Code as follows:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Sub NewPass()
      Dim PassCheck As String
      GetDatabase()
      'Check if there is a password
      SQLString = "SELECT EmployeeID, Password, Deleted FROM Employee "
      SQLString += "WHERE EmployeeID= " &amp; UserID
      Try
          connection.Open() ' Open Connection
          If ConnectionState.Open.ToString = "Open" Then
              command = New System.Data.OleDb.OleDbCommand(SQLString, connection)
              datareader = command.ExecuteReader()
              If datareader.HasRows Then
                      If datareader.Item("Deleted") = False Then
                      'Password check
                      outputString = datareader.Item("Password").ToString
                      Else
                          outputString = ""
                      End If
              End If 'recordset has rows
              datareader.Close()
          End If
      Catch ex As Exception 'Display Error message
          MessageBox.Show("Error accessing database", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
      End Try
      connection.Close()
  
      PassCheck = outputString
  
      If String.IsNullOrEmpty(PassCheck) = True Then
  
          GetDatabase()
          SQLString = "UPDATE Employee SET "
          SQLString += "Password = '" &amp; Password &amp; "' "
          SQLString += "WHERE EmployeeID = " &amp; UserID
          'Try
          connection.Open()
          If ConnectionState.Open.ToString = "Open" Then
              'Update Password
              command = New System.Data.OleDb.OleDbCommand(SQLString, connection)
              command.ExecuteNonQuery()
  
              MainMenuForm.Show()
              Me.Hide()
          Else
              outputString = ""
              MessageBox.Show("Error opening connection")
          End If
          connection.Close()
          'Catch ex As Exception
  
          'End Try
      Else
          MessageBox.Show("This Account has a password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
          FirstTimeButton.Show()
          FirstTimeBool = False
      End If
  
  End Sub
  </code></pre>
  
  <p>GetDatabase()</p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Sub GetDatabase()
      'Locates the Database
      Try
          ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data "
          ConnectionString += "Source=" &amp; System.Windows.Forms.Application.StartupPath &amp; "\PharmacyDatabase.accdb "
          connection = New System.Data.OleDb.OleDbConnection(ConnectionString)
      Catch ex As Exception 'No Database Found
          MessageBox.Show("No Database Found in \Debug", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
      End Try
  End Sub
  </code></pre>