Hi all,
Thanks for the hints and tips.
I managed to have the sample program work by below code.I know there may be problems on the code.Grateful for any comments.
1.In sqlQuery1,add params according to the primary key field and the field to be updated;
2.write deleteSql,updateSql statement;
3.For delete,in dbnavigator1:
if button=nbDelete then
begin
sqlQuery1.ApplyUpdates;
sqlTransaction1.Commit;
end;
{
After delete,the dataSet closed so I need to re-open it:
}
if sqlTransaction1.active=false then
begin
sqlTransaction1.active:=true;
sqlQuery1.active:=true;
sqlQuery1.open;
end;
{
as the table contains Chinese character fields,I use a routine to have lazarus print Chinese font correctly.
function utf8DataSet:TSqlQuery;
begin
....
result:=someVar;
end;
In the form's onCreate event:
sqlQuery1:=utf8DataSet;
But after deletion,the Chinese font issue ocurred again,they are not recognizable!
So I fixed the issue by adding below code in sqlQuery1's afterScroll event:
sqlQuery1:=utf8DataSet;
}
4.For update,insert,in dbnavigator1:
if button=nbPost then
begin
sqlQuery1.edit;
sqlQuery1.ApplyUpdates;
sqlTransaction1.CommitRetaining;
end;