Page 1 of 1

Updating records using TMyQuery in Borland C++

Posted: Mon 20 Oct 2008 21:54
by tbkirch
I'm having trouble updating a recordset using the TMyQuery object. FetchAll is True and CachedUpdate is True. My code looks like this:
MyQuery->SQL->Text= SQLstr;
MyQuery->Execute();
int rowCount= MyQuery->RecordCount;
double v = 0.0;

for(int i=0; iEdit();
v=offsetVec.at(i);
MyQuery->FieldByName("Offset")->AsFloat = v;
MyQuery->Post();
//MyQuery->ApplyUpdates();
MyQuery->Next();
}

}
//MyQuery->ApplyUpdates();
MyQuery->SQL->Clear(); Clear causes a failure.
MyQuery->Close();

offsetVex.size() does equal rowCount. This fails with a "Update failed" error on the ->Close statement. If I replace the ->AsFloat = v; with AsFloat = 99.9; then the update occurs. However, I think that this is an artifact, since if I update just the first record (replace rowCount in the loop statement by 1) all of the records are updated, although I do get an Upate Failed error on the close statement. If I do an ApplyUpdates within the loop after the Post, I also get an Update Failed Error on the ->Next statement.

How can I update the individual records of the recordset?

Thanks

Posted: Wed 22 Oct 2008 07:06
by Challenger
Please provide the update statement.

Updating records using TMyQuery in Borland C++

Posted: Thu 23 Oct 2008 15:44
by tbkirch
Sorry, I don't understand. Are you asking for an update statement beyond the MyQuery->ApplyUpdates()? Or are you suggesting that I need to include an Update statement of some sort (maybe an SQL statement?)in addition to what I showed. I've showed everything that is related. If I'm missing some overall design issue I'd sure appreciate a pointer on where to find this in the documentation.
Thanks

Posted: Fri 24 Oct 2008 12:53
by Challenger
I thought you have set the update statement using TMyQuery.UpdateSQL. Please provide the structure of your table and specify the version of MySQL you are useing.

Posted: Fri 24 Oct 2008 16:53
by tbkirch
Thanks for looking at this. I don't know why, but when I reproduced this code in a smaller "test" routine, and added back the MyQuery->ApplyUpdates before closing the recordset, it worked without generating the error. So, life is good.