syloux
asked on
Working with StartTransaction ???
How can I use correctly StartTransaction ?
I have this :
( Query1.CachedUpdate := True )
Database1.Open ;
Database1.StartTransaction
With Query1, Sql Do
Begin
Close ;
Clear ;
Add('INSERT INTO Test') ;
Add('VALUES (:Username, :LongName)') ;
ParamByName('Username').As
ParamByName('Longname').As
ExecSql ;
End ;
Query1.ApplyUpdates ;
Database1.Commit ;
Query1.CommitUpdates ;
But when I run it, I have and error messsage on Query1.ApplyUpdates :
"Dataset not in edit or insert mode."
What can I do ?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i guess cached updates are only usefull with an select-query,
you get the error because you don't call query.edit or query.insert,
which may cause a dataset not open error, because you can't open a insert query
if you want the capability of cached updates, then use a select-query,
open the query,
insert your new records with the insert method,
supply your fieldvalues with query.fielsbyname().as.. := whatever
post the insert and
start again with a new record,
if you are ready then you do a applyupdate
meikl ;-)
you get the error because you don't call query.edit or query.insert,
which may cause a dataset not open error, because you can't open a insert query
if you want the capability of cached updates, then use a select-query,
open the query,
insert your new records with the insert method,
supply your fieldvalues with query.fielsbyname().as.. := whatever
post the insert and
start again with a new record,
if you are ready then you do a applyupdate
meikl ;-)
Hi,
Using my solution you don't need to think what the query does (select, insert, etc.) because you check for pending updates first.
The second thing is that TDatabase.ApplyUpdates does all the transaction stuff internally (starts a transaction, commits or rolls back and clears the updates cache) for you.
Regards, Geo
Using my solution you don't need to think what the query does (select, insert, etc.) because you check for pending updates first.
The second thing is that TDatabase.ApplyUpdates does all the transaction stuff internally (starts a transaction, commits or rolls back and clears the updates cache) for you.
Regards, Geo
I'm not sure but try this:
Database1.Open ;
With Query1, Sql Do
Begin
Close ;
Clear ;
Add('INSERT INTO Test') ;
Add('VALUES (:Username, :LongName)') ;
ParamByName('Username').As
ParamByName('Longname').As
ExecSql ;
end;
if Query1.UpdatesPending then
Database1.ApplyUpdates([Qu
End ;
Regards, Geo