Share via

Failed Update data by using a TableAdapter in .NET Framework applications

qp 26 Reputation points
2024-01-10T16:34:04.7466667+00:00
In Visual studio 2022, I have created a VB forms connect with my table in SQL. I can add new record in table but not update. Here is the code

Private Sub ButtonUpdate_Click(sender As Object, e As EventArgs) Handles ButtonUpdate.Click 
     Try 
         Me.Validate() 
         Me.EmployeeBindingSource.EndEdit() 
         Me.EmployeeTableAdapter.Update(Me.HRDataSet.Employee) 
         MsgBox("Update successful") 
     Catch ex As Exception 
         MsgBox("Update failed") 
     End Try 
 End Sub
Developer technologies | VB

1 answer

Sort by: Most helpful
  1. Spearman 0 Reputation points
    2026-03-29T16:28:01.35+00:00

    I am using the same code and am having the same problem. @Jiachen Li-MSFT I am not getting an exception. I get the msgbox "Update successful". The data table on the form shows the new data. The edited data is just not writing to the database. When I next close and then open the project the data has not been changed. Button 1 changes the data in the DataGridView. Button2 doesn't update the (Access) database.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

      MatchedBettingDataSet.Bets(1).Site = "New Web Site Name"
    

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    
        Try
    
            Me.Validate()
    
            Me.MatchedBettingDataSetBindingSource.EndEdit()
    
            Me.BetsTableAdapter.Update(Me.MatchedBettingDataSet.Bets)
    
            MsgBox("Update successful")
    
        Catch ex As Exception
    
            MsgBox("Update failed")
    
        End Try
    
    End Sub
    

    In the past I've done everything by SQL statements but this is the first time I've used the binding method. Any help would be appreciated.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.