Skip to content

Rowchanged event and update confilict

ali sag

Asked Aug 13, 2008, 7:25 AM EDT1 answer
Share
LinkedInX
am trying to take under control of changing datarows. when there is a change i want to ask user whether he/she wants to save changes or discard changes. to accomplish this i am using rowchanged event

C#
private void Form1_Load(object sender, EventArgs e)
{
     this.kisiTableAdapter.Fill(this.denekDataSet.Kisi);
   
     denekDataSet.Kisi.KisiRowChanged += new denekDataSet.KisiRowChangeEventHandler(Kisi_KisiRowChanged);

}


void Kisi_KisiRowChanged(object sender, denekDataSet.KisiRowChangeEvent e)
        {
            DataRowAction drc = e.Action;
            if (drc == DataRowAction.Change)
            {
                DialogResult dr = MessageBox.Show("do you want to save changes!", "warning", MessageBoxButtons.YesNo);
                if (dr == DialogResult.No)
                {
                    e.Row.RejectChanges();

                }
     
            }
        }


when there is a change this event works. and if user choice is "no" it works perfectly. but dialog result is "yes", there is a problem appears. changes are not apply to the database(restart the program). everything same as before the change action.

i tried different ways but it causes different errors(exception).

C#
void Kisi_KisiRowChanged(object sender, denekDataSet.KisiRowChangeEvent e)
        {
            DataRowAction drc = e.Action;
            if (drc == DataRowAction.Change)
            {
                DialogResult dr = MessageBox.Show("do you want to save changes!", "warning", MessageBoxButtons.YesNo);
                if (dr == DialogResult.No)
                {
                    e.Row.RejectChanges();

                }else 
                {
                   kisiTableAdapter.Update(denekDataSet.Kisi);
                }

     
            }
        }


after changing it calls many times messagebox for asking choice then produces InvalidOperationException and stops.

how can i solve this problem, it makes me anger and tired.

please help me , or show me a different way.

my intention is tracking changes and asking right question.

thanks for interests

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    0
    it is not a good idea to make an entire update for each row. you can create a windows service that updates hole data for a constant period I mean each 15 minutes windows service updates the data base
    0