Question dataset.HasChanges always return True problem

adshocker

Well-known member
Joined
Jun 30, 2007
Messages
180
Programming Experience
Beginner
hi all,

below is the code i have..

VB.NET:
    Private Sub fknluser_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Me.Validate()

        Me.KnlrolesBindingSource.EndEdit()
        Me.Knl_usersBindingSource.EndEdit()
        Me.Knl_user_rolesBindingSource.EndEdit()

        If Me.Dsknluser.HasChanges = True Then
            Dim result As DialogResult = ShowYesNoCancel("Do you want to save changes?")
            If result = Windows.Forms.DialogResult.OK Then
                Record_Update()
            ElseIf result = Windows.Forms.DialogResult.Cancel Then
                e.Cancel = True
            End If
        End If
    End Sub

    Private Sub fknluser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Initialize()

        Knl_rolesDataAdapter.Fill(Me.Dsknluser.knl_roles)
        Knl_usersDataAdapter.Fill(Me.Dsknluser.knl_users)
        Knl_user_rolesDataAdapter.Fill(Me.Dsknluser.knl_user_roles)
    End Sub

what happens is when the form is loaded, data is also filled. so to test if it's working, i immediately close the form after it is loaded without doing any changes but then i get the messagebox even still.

is this a normal behavior or am i doing something wrong?

thanks
 
By calling endedit on each of the tables arent you essentially saying the current record has updated; regardless whether the values actually changed or not.
 
hi,

thanks for the response.

if i don't call the endedit, even if i made changes to the current row, dataset.HasChanges will always return false.

how do i check for any changes made in my datatables? searching thru the net brought me to use that sample but it's not working as expected.

thanks.
 
In the immediate window, just call

Me.Dsknluser.knl_roles.GetChanges()
Me.Dsknluser.knl_users.GetChanges()
Me.Dsknluser.knl_user_roles.GetChanges()

Which rows are changed, and what is their rowstate?
 
hi,

thanks...

after entering Me.Dsknluser.knl_users.GetChanges() in the Immediate Window, i get

Me.Dsknluser.knl_users.GetChanges()
The expression cannot be evaluated while in run mode.

so then i click pause and then i get

Me.Dsknluser.knl_users.GetChanges()
Unable to evaluate the expression.

not sure if i'm doing it right.
 
Put a breakpoint on the first call to endedit. This ensures your app stops at a point where all the objects youre referencing actually exist and are in context :)

Then run the immediate window statements

Then step over the 3 endedits

Then run the immediate window statements again

Was it the endedits that causes the changes? Was any data actually edited? (Are you sure? compare the Original and currentversions of the row)
 
Back
Top