Link to home
Start Free TrialLog in
Avatar of monz
monz

asked on

updating database table using transaction

i use delphi 5

i want update a database table using database transactions

i have a datamodule with a database component (database1) and some table components (table1, table2...)

i wrote for exemple

datamodule.table1.database.starttransaction;
datamodule.table1.edit;
datamodule.table1.fieldbyname('NAME1').AsString := 'something';
......
datamodule.table1.post;
datamodule.table1.database.commit;

the error message i receive is "Nested transaction not supported"

why?

is there an implicit call to starttransaction inside the edit procedure?


Avatar of linus66
linus66

when you start transaction see to that you don have another transaction pending. you can always prevent this by a commit before starttransaction also do a try except routine to handle exceptions...
try
  if datamodule.table1.database.InTransaction Then
    datamodule.table1.database.Commit;

  datamodule.table1.database.starttransaction();

  datamodule.table1.edit();
  datamodule.table1.First();
  while not datamodule.table1.eof do
  Begin
    datamodule.table1.fieldbyname('NAME1').AsString := 'something';
    datamodule.table1.post();
  End;
  if datamodule.table1.database.InTransaction Then
   datamodule.table1.database.commit();
except
  on e:exception do
  begin
     ShowMessage(e.message)
     datamodule.table1.database.RollBack();
  end;
end;

hope it gives a hunt to you..

Avatar of monz

ASKER

nothing is changed
when i call the post metod i receive the same erro message
ASKER CERTIFIED SOLUTION
Avatar of linus66
linus66

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
monz:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.