troubleshooting Question

Delphi 2005 BDP get scope_identity()

Avatar of dygj
dygj asked on
Delphi
2 Comments1 Solution449 ViewsLast Modified:
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;
 
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros