Failed to update records in a table

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
lohmann
Posts: 2
Joined: Mon 16 Nov 2009 07:18

Failed to update records in a table

Post by lohmann » Thu 26 Nov 2009 16:13

Hi,

I would like to update student data with the following codesnippets, but it would throw out the message said 'Update failed. Found 0 records', but as the showmessage showed, there was a record existed!

====codesnippets====

with TUniTable.Create(nil) do
try
Connection := conSQLite;
TableName := 'Student';
Filtered := False;
Filter := 'Ref=' + IntToStr(StudentRef);
Filtered := True;
Active := True;
try
ShowMessage(IntToStr(RecordCount )); // 1
Edit;
FieldByName('FullName').AsString := FullName;
//......
Post;
Result := True;
except
Result := False;
MessageDlg('Failed to save modification!', mtError, [mbOK], 0);
end;
finally
Close;
Free;
end;

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Fri 27 Nov 2009 08:26

When you call the Post method, UniDAC executes an UPDATE statement. After that UniDAC gets count of rows affected by UPDATE. If the UPDATE statement changes no rows, this error is raised.

Maybe it is because your table does not have a primary key. Check that the table has a primary key.

Post Reply