ali sag

ali sag

  • NA
  • 1
  • 0

rowchanged event and update confilict

Aug 13 2008 11:25 AM
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


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).



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

Answers (1)