Question Dataset haschanges method problem

Abdelghafour

New member
Joined
Nov 3, 2008
Messages
4
Programming Experience
Beginner
Hi,

I have 2 problems with the haschages method

1 : when i do like this:

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

    Me.Validate()
    Me.DataTable1BindingSource.EndEdit()


    If Me._dataSet1.HasChanges() Then
      If MessageBox.Show("DS has changes. Really exit?", "", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No Then e.Cancel = True

    End If

  End Sub
the haschanges method returns always true even if i odes not made any change to the data.
2:
I'm using the bindingnavigator, when i navigate between the rows the haschanges method returns always true even if i does not made any change to the data

this is stranger

the endedit method seems mading a change in the dataset

please help
 
I recognise that code snippet, having written it :)

You've changed the data, honestly you have! "Just navigating" won't change anything.

Call:

VB.NET:
Dim chg as Dataset1.DataTable1 = _dataSet1.DataTable1.GetChanges()

'put a breakpoint on the line of code after this comment

Now go and look at the chg DataTable.. that's what you've changed since you downloaded the data! All Additions, Modifications and Deletions are shown
 
changes = nothing

Hi cjad,

I have many binding source in the form, for the comboboxe's data sources, so i wrote this code :

VB.NET:
Dim clientschanges As BMSDataSet.ClientsDataTable = Me.BMSDataSet.Clients.GetChanges()
        Dim payschanges As BMSDataSet.PaysDataTable = Me.BMSDataSet.Pays.GetChanges()
        Dim monnaieschanges As BMSDataSet.MonnaiesDataTable = Me.BMSDataSet.Monnaies.GetChanges()
        Dim villeschanges As BMSDataSet.VillesDataTable = Me.BMSDataSet.Villes.GetChanges()
        Dim formesjuridique As BMSDataSet.Formes_JuridiquesDataTable = Me.BMSDataSet.Formes_Juridiques.GetChanges()
        Dim tarifchanges As BMSDataSet.TarifDataTable = Me.BMSDataSet.Tarif.GetChanges()



        Me.ClientsBindingSource.EndEdit()

all the changes = nothing when i test it.

maybe because the comboboxe's data sources :confused:.
 
another test

I have tested it in another form which contain only one databindingsource :

VB.NET:
Private Sub Monnaie_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim reponse As DialogResult
        Me.Validate()
        Dim monnaieschanges As BMSDataSet.MonnaiesDataTable = Me.BMSDataSet.Monnaies.GetChanges()

        Me.MonnaiesBindingSource.EndEdit()
        
        If Me.BMSDataSet.HasChanges Then
            reponse = MessageBoxEx.Show("Voulez vous enregistrer les modifications avant de partir ?", "Enregistrer avant de partir", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
            If reponse = Windows.Forms.DialogResult.Yes Then
                SaveAndRefresh()
            ElseIf reponse = Windows.Forms.DialogResult.Cancel Then
                e.Cancel = True
            End If
        End If
    End Sub

the same thing , changes = nothing.

it's really stranger .
any ideas
 
You GetChanges (nothing) and then you EndEdit, which may commit a change, and then you check HasChanges

Doesnt this strike you as the wrong way round to do these things?
 
You'r right

hi cjad,

i have tried the getchanges after the end edit and its contain only the current row, but the data is the same without any change, so i don't understand what is the change that occur to the data.



excuse me, i'm new with .net.


thank you
 
Maybe you should attach an event handler to the RowUpdated event of the relevant data table and see exactly what youre changing. I can't help you out because you havent provided any code. Please dont just dump the entire code for your program into your post and expect me to pick through it; analyse this one yourself.

I've made an example project with a DataTable loaded with data, BindingSource and DataGridView, BindingNavigator, a button that calls EndEdit() and a button that MessageBoxes the result of HasChanges()
With it I've navigated tens of times, called EndEdit and I have never managed to get HasCHanges() to return true just from a nav. You can have the example project if you like, to see if on your machine it somehow returns true from just navigating, but I doubt it will
 

Latest posts

Back
Top