mercredi 1 avril 2015

update on datagridview does not update local db with update statement

I have a login form that should be updating my local db with the current logged on users. On the form_load it pulls all users from the DB to a hidden datagridview via tableadapter and then refreshes it every 5 seconds via a timer.


on login it disables the timer, changes a single value on the datagridview and then runs the table adapter.update statement. On completion it enables the timer again to refresh the datagridview.


My problem is, at runtime for testing, the datagridview is visible and can see it changes the value for the user, but once it refreshes, its back to the old value. the code for the loginBtn_Click and Timer1_Tick is below :



Private Sub LoginBtn_Click(sender As Object, e As EventArgs) Handles LoginBtn.Click
If PWTxt.Text = PW Then
If DataGridView1.Item(4, temppos).Value = False Then
Timer1.Enabled = False
LoggedInID = tempID
DataGridView1.Item(4, temppos).Value = True
Me.LoginTableAdapter.Update(LoginDataSet)
MenuForm.Show()
MenuForm.Focus()
Timer1.Enabled = True
Else
MsgBox(Trim(tempID) & " is currently logged in. Please contact your Systems Administrator.")
End
End If
Else
MsgBox("Invalid Password")
LoggedInID = ""
End If
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Try
Me.LoginTableAdapter.Fill(Me.LoginDataSet.Login)
Catch ex As Exception
MsgBox("Failed to refresh. Error : " & vbCrLf & ex.Message)
End Try
End Sub


Any explanation or resolution would be appreciated. Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire