Page 1 of 1

Only one field updated

Posted: Fri 05 Dec 2008 20:09
by guest2
Using Borland C++ and MySQL Components
For some reason, only one field is updated.

void __fastcall TForm1::BitBtnUpdateClick(TObject *Sender)
{
// MyTable1 is in Edit mode
MyTable1->FieldByName("field1")->AsString = Edit1->Text.Trim(); // line1
MyTable1->FieldByName("field2")->AsString = Edit2->Text.Trim(); // line2
MyTable1->FieldByName("field3")->AsString = Edit3->Text.Trim(); // line3
MyTable1->Post();
}

After posting, only the first field takes the new value. For some reason field2 and field3 do not get updated.
If I comment out line1, field2 would get updated and field3 would not, as if the assignment works only once.

Even step-by-step debugging shows that after line3 is executed the field value remains unchanged.

Any reason why?

Thanks.

Posted: Fri 05 Dec 2008 21:50
by guest2
Never mind.
As soon as line1 is executed, the MyDataSource->OnDataChange event is fired. In the event handler, I was updating the Edit1,2,3 fields with the current values from the DataSet, which in turn are the original values.
I added the if (State!=dsInsert && State!=dsEdit) condition into the event handler which solved my problem.
Thanks for reading my post anyway.