none
dataset.haschanges detects changes even where there are none. RRS feed

  • Question

  • BH

    Hi i've been struggling with this several days now.  I'm using ambtransdataset.hasChanges method, but somehow this method detects changes in dataset even when there are none.  The code i'm using is below.  What am i doing wrong?

    Thanks so much for your help.

    Aron

     

     

            bool CheckForChangesInTripOrClientDataset(bool Continue)

            {

                CurrencyManager ClientsGridCurrencyManager = (CurrencyManager)this.BindingContext[clientsDataGridView1.DataSource, clientsDataGridView1.DataMember];

                CurrencyManager TripsGridCurrencyManager = (CurrencyManager)this.BindingContext[tripsDataGridView1.DataSource, tripsDataGridView1.DataMember];

                ClientsGridCurrencyManager.EndCurrentEdit();

                TripsGridCurrencyManager.EndCurrentEdit();

     

     

                if (ambtrans4DataSet.HasChanges(DataRowState.Modified | DataRowState.Added))

                {

                    switch (MessageBox.Show("Do you want to save changes?",

                              "WonderWord",

                              MessageBoxButtons.YesNoCancel,

                              MessageBoxIcon.Question))

                    {

                        case DialogResult.Yes:

                            this.tripsBindingSource.EndEdit();

     

                            if (ContinueToSaveTripOrClient(true) == true)

                            {

                                Continue = true;

                                clientsDataGridView1.Enabled = true;

     

                                //ambtrans4DataSet.RejectChanges(); 

                                break;

                            }

                            else

                            {

                                Continue = false;

                                break;

                            }

     

                        case DialogResult.No:

                            ambtrans4DataSet.RejectChanges();

                            clientsDataGridView1.DataSource = new BindingSource();

                            this.clientsDataGridView1.DataSource = this.clientsBindingSource;

                            clientsDataGridView1.Enabled = true;

     

                            Continue = true;

     

                            break;

     

                        case DialogResult.Cancel:

                            Continue = false;

                            break;

     

                    }

                    return Continue;

                }

                else

                {

                    Continue = true;

                    return Continue;

                }

            }


    Thanks Aron www.EvidenceForTorah.comxa.com
    Tuesday, May 3, 2011 1:59 PM

Answers

All replies

  • BH

    Hi i've been struggling with this several days now.  I'm using ambtransdataset.hasChanges method, but somehow this method detects changes in dataset even when there are none.  The code i'm using is below.  What am i doing wrong?

    Thanks so much for your help.

    Aron

     

            bool CheckForChangesInTripOrClientDataset(bool Continue)

            {

                CurrencyManager ClientsGridCurrencyManager = (CurrencyManager)this.BindingContext[clientsDataGridView1.DataSource, clientsDataGridView1.DataMember];

                CurrencyManager TripsGridCurrencyManager = (CurrencyManager)this.BindingContext[tripsDataGridView1.DataSource, tripsDataGridView1.DataMember];

                ClientsGridCurrencyManager.EndCurrentEdit();

                TripsGridCurrencyManager.EndCurrentEdit();

     

     

                if (ambtrans4DataSet.HasChanges(DataRowState.Modified | DataRowState.Added))

                {

                    switch (MessageBox.Show("Do you want to save changes?",

                              "WonderWord",

                              MessageBoxButtons.YesNoCancel,

                              MessageBoxIcon.Question))

                    {

                        case DialogResult.Yes:

                            this.tripsBindingSource.EndEdit();

     

                            if (ContinueToSaveTripOrClient(true) == true)

                            {

                                Continue = true;

                                clientsDataGridView1.Enabled = true;

     

                                //ambtrans4DataSet.RejectChanges(); 

                                break;

                            }

                            else

                            {

                                Continue = false;

                                break;

                            }

     

                        case DialogResult.No:

                            ambtrans4DataSet.RejectChanges();

                            clientsDataGridView1.DataSource = new BindingSource();

                            this.clientsDataGridView1.DataSource = this.clientsBindingSource;

                            clientsDataGridView1.Enabled = true;

     

                            Continue = true;

     

                            break;

     

                        case DialogResult.Cancel:

                            Continue = false;

                            break;

     

                    }

                    return Continue;

                }

                else

                {

                    Continue = true;

                    return Continue;

                }

            }


    Thanks Aron www.EvidenceForTorah.comxa.com
    • Merged by Cookie Luo Wednesday, May 4, 2011 5:46 AM duplicate
    Sunday, May 1, 2011 8:21 PM
  • There is no concept of dataset in the C# language standard. 

    The ADO.Net dataset forum is under the data platform development category.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Sunday, May 1, 2011 8:53 PM
  • Hi,

    are you aware that if you bind controls to your data, and just, let's say type a space, and then remove that space immediately, it is seen as a change, even though the original value and the changed value are equal?

    It is often with bound controls, that by loading a form, events are triggered that cause this kind of changes.

    Try to find out, by setting breakpoints, at what point the change is happening.


    Regards, Nico
    Tuesday, May 3, 2011 2:15 PM
  • BH

    Nico thanks for your reply.  I've tried to pinpoint where the change is happening and i don't see it.  Yes i'm aware that when a space is entered and deleted it is considered as a change.  The strange thing is that, i'm only having this problem when i put my fields into a panel that is inside a panel.  I have a previous version of my software where it is the same exact code except that the fields are in an old panel, and there it is working fine.  Is there an an event or method that can show the specific changes that it is picking up?

    Thanks

    Aron


    Thanks Aron www.EvidenceForTorah.comxa.com
    Wednesday, May 4, 2011 2:40 AM
  • Hi

    Please don't post duplicate thread. I merge the two shortly.

    Thanks for your understanding.


    Cookie Luo[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, May 4, 2011 5:45 AM
  • You could try creating an event handler for either the DataTable.RowChanged or RowChanging event and setting a breakpoint in the handler. When it breaks, the call stack *may* help you determine what caused the change.
    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Sunday, May 8, 2011 5:01 AM