Link to home
Start Free TrialLog in
Avatar of dygj
dygj

asked on

Delphi 2005 BDP get scope_identity()

Delphi 2005, mssql server 8  Asp .net application


I need to get the new identity value returned after doing an insert into.
Statement are:
bdpcommand_insert.commandtext='Insert into mytable (myfield1,myfield2) values (?,?)'
bdpcommand_getid.commandtext='select scop_identity() as ID'
bdpcommand_insert.parameters[0]:=textbox1;
bdpcommand_insert.parameters[1]:=textbox2;
Mybdpconenction.open;
trans:mybdpconnection.begintransaction;

bdpcommand_insert.executeNonQuery;
myid=integer(bdpcommand_getid.executescalar);
trans.commit;

But I only get 0 as myid, ie the new identity value is not returned.

Any hints how to get the identity of a insert into statement?

(I figured it out how to do it if you insert a new record into a grid reading an article
www.howtodothings.com/ViewArticke.aspx?Article)762  , but now I am inserting one records from a web form)

I also tried with the following statement without results:
aread=bdpcommand_getid.executereader;
while aread.read do
myid=aread['id'].tostring;
 
ASKER CERTIFIED SOLUTION
Avatar of BlackTigerX
BlackTigerX

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
Avatar of dygj
dygj

ASKER

Could not get it working without parameters either. I created a new query using all parameters from the first one to get the new id, and that works.

Anyway some more bugs found in delphi
- cut/past/print will not work anymore if you save desctop settings.
- after using the depoy manager  all form designs are invisible.
- renaming a form with visual objects will crash most things.
- depoying an asp application with upgrade 3 is only possibile with many manuall changes.
(http://www.drbob42.com/examines/examin66.htm)