Only one field updated

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
guest2
Posts: 2
Joined: Fri 05 Dec 2008 19:52

Only one field updated

Post by guest2 » Fri 05 Dec 2008 20:09

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.

guest2
Posts: 2
Joined: Fri 05 Dec 2008 19:52

Post by guest2 » Fri 05 Dec 2008 21:50

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.

Post Reply