TLiteTable Post Error - Update failed Found 0 records
Posted: Thu 28 Jul 2016 20:00
I'm using the evaluation installation of the LiteDAC components in RAD Studio 10.1 Berlin to convert a BDE legacy application that used the InfoPower TwwTable with the TLiteTable component. I've been able to open the connection to the SQLite database and connect TLiteTable objects to the TwwDataSource components that feed the TwwDBGrid to list table records and even apply different sort orders. My first attempt to edit a TLiteTable in a start up utility procedure that must assign a new value to the License table record failed on the Post call generating an EDatabaseError Exception indicating Update failed Found 0 records after the RecordCount property returned > 0. I've found examples of using the TLiteTable Edit, FieldByName and Post calls so I don't understand what I'm doing wrong. I'm hoping the LiteDAC components will be a direct substitution migration path for the application. Any help or suggestions would be appreciated!
The utility procedure code:
FWIW, I tried changing the 'License' string for the TableName property to '"License"' thinking there might be a problem with the field name being the same as the table name but that generated an error indicating the field did not exist whereas the correct field name executed correctly before the Post error. How can I access the field but then get an error about 0 records?
The utility procedure code:
Code: Select all
WC5NewLite := TLiteConnection.Create(Application);
try
With WC5NewLite do
begin
Database := stTgtDBFile;
Options.ForceCreateDatabase := False;
Options.Direct := True;
Options.DateFormat := 'mm-dd-yyyy';
LoginPrompt := False;
Connect;
lgRtn := True;
end;
except
lgRtn := False;
Screen.Cursor := crDefault;
Application.ProcessMessages;
MessageDlg('Cannot open a source LiteDAC connection to the SQL database',mtError,[mbOk],0);
end;
if lgRtn then
begin
OpenLiteSQLDB(WC5NewLite, stTgtDBFile);
tblTgt := TLiteTable.Create(Application);
With tblTgt do
begin
Connection := WC5NewLite;
TableName := 'License';
Open;
if RecordCount > 0 then
begin
Edit; // Reassign license for setup
FieldByName ('License').AsString := 'Setup';
Post; <<< Exception occurs
end else