Results 1 to 8 of 8

Thread: Datagridview update not working

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Datagridview update not working

    I am trying to update my DGV with the following code. i have generated SQL update command in the tableadapter. but still the changes are not affecting the DB.

    Any suggestions?

    Code:
    If Me.TabControl1.SelectedTab.Equals(Locn) Then
                If MWLocations.HasChanges Then
                    Try
                        Me.LocationsBindingSource.EndEdit()
                        Me.MWLocations.AcceptChanges()
                        Me.LocationsTableAdapter.Update(Me.MWLocations.Locations)
                        MsgBox("            Update successful       ")
                    Catch ex As Exception
                        MsgBox("            Update failed       ")
                    End Try
                End If
            End If

  2. #2
    Addicted Member
    Join Date
    Oct 2008
    Posts
    152

    Re: Datagridview update not working

    There are hardly any reasons to ever have to call AcceptChanges. By stating that, you are resetting the row states of your dataset/datatable and telling it that none of the rows have changed.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: Datagridview update not working

    alright, even after removing it the changes are not affecting the DB

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: Datagridview update not working

    anyone plz help !!

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Datagridview update not working

    I wish I had a $ for every time I've posted this. It's several times a week on average.

    The first thing to do is to test the return value of your Update method. If it's zero then there are no changes in your DataTable to save, at least with the SQL you're executing. If it's not zero then data is being saved and you're simply looking for it in the wrong place or at the wrong time, which is not as silly as it sounds.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: Datagridview update not working

    how do i test the return value of my Update method?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Datagridview update not working

    Quote Originally Posted by LuxCoder View Post
    how do i test the return value of my Update method?
    It's just a function like any other. How do you normally test the return value of a function?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: Datagridview update not working

    by using msgbox ?

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