Results 1 to 3 of 3

Thread: vb net ado cannor update record in SQL database

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2008
    Posts
    47

    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

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    108,499

    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

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    108,499

    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
  •  



Click Here to Expand Forum to Full Width