I have a data-bound DataGridView with a BindingSource and a TableAdapter all together it makes two column leaderboard linking back to an Access DB
I need to be able to check whether a particular record exists and, if it does exist, then update it with new info. If it does not exist then add it.
My code so far after many permutations and still not working is:
At present it will add a new record to the DGV but not save it to the database and I haven't found a reliable way of updating the dataset/tableCode:Private Sub UpdateLeaderboard(ByVal jName As String, jWins As Integer) Dim test As Boolean = False 'Check whether the name already exists Dim jRow As DataRow = SsrDataSet.JockeyLeaderboard.NewRow For Each row In JockeyLeaderboardDataGridView.Rows If jName = row.Cells(0).Value Then jWins = row.Cells(1).Value test = True jWins += 1 Exit For End If Next If test = True Then 'update the recoed with new info End If If test = False Then 'the name is not present so add it Dim MyNewRow As DataRow MyNewRow = SsrDataSet.JockeyLeaderboard.NewRow With MyNewRow .Item(0) = jName .Item(1) = jWins End With SsrDataSet.JockeyLeaderboard.Rows.Add(MyNewRow) SsrDataSet.JockeyLeaderboard.AcceptChanges() End If Try Me.Validate() Me.JockeyLeaderboardBindingSource.EndEdit() Me.JockeyLeaderboardTableAdapter.Update(Me.SsrDataSet.JockeyLeaderboard) 'MsgBox("Update successful") My.Computer.Audio.Play(My.Resources.notify, AudioPlayMode.Background) Catch ex As Exception MsgBox(ex) End Try End Sub
Please point out the error of code
Thanks





Reply With Quote
