vb net ado cannor update record in SQL database
Hello
I have this code in a button to update a new record in a dbgridview but raises exeption, if I click a cell of previous record then it accepts the new record (stops edit mode)
Code:
Code:
Private Sub BindingNavigator1_RefreshItems(sender As Object, e As EventArgs) Handles BindingNavigator1.RefreshItems
' Me.Table1BindingSource.EndEdit()
Me.BindingContext(DataSet11, "Table_1").EndCurrentEdit()
If DataSet11.HasChanges Then
Try
SqlDataAdapter1.Update(DataSet11, "Table_1")
DataSet11.AcceptChanges()
Catch eUpdate As System.Exception
'Throw eUpdate
MsgBox(eUpdate.Message.ToString)
End Try
End If
End Sub
Re: vb net ado cannor update record in SQL database
Let's start by making your code easier to read. Please don't submit a post when the formatting is a mess.
Code:
Private Sub BindingNavigator1_RefreshItems(sender As Object, e As EventArgs) Handles BindingNavigator1.RefreshItems
' Me.Table1BindingSource.EndEdit()
Me.BindingContext(DataSet11, "Table_1").EndCurrentEdit()
If DataSet11.HasChanges Then
Try
SqlDataAdapter1.Update(DataSet11, "Table_1")
DataSet11.AcceptChanges()
Catch eUpdate As System.Exception
'Throw eUpdate
MsgBox(eUpdate.Message.ToString)
End Try
End If
End Sub
Re: vb net ado cannor update record in SQL database
As for the issue, you don't have code "in a button". You've shown us the RefreshItems event handler for a BindingSource. Perhaps if you were to provide an actual explanation of what you're actually trying to achieve, we could determine why the code you have doesn't achieve it and what is the best way to do so. Also, if an exception is thrown then tell us where and what. We shouldn't have to guess what you're trying do from code that doesn't do it and we should have to guess what actually happens and where either. You need to provide ALL the relevant information.