Page 1 of 1

Failed to update records in a table

Posted: Thu 26 Nov 2009 16:13
by lohmann
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;

Posted: Fri 27 Nov 2009 08:26
by Plash
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.