|
-
May 17th, 2022, 03:02 AM
#1
Thread Starter
Member
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
-
May 17th, 2022, 03:44 AM
#2
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
-
May 17th, 2022, 03:48 AM
#3
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|