[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Getting Identity of row inserted id MS SQL database

Posted on 2004-10-21
6
Medium Priority
?
229 Views
Last Modified: 2010-04-05
I am trying to get the identity of a record added with an ado dataset the sql in the dataset is :-

Insert into Timetran
(casecode, personno, date .........)
Values
(:ccode , :pno, :tdate, ................)
select @@IDENTITY as 'Ident'

when I then open the adoDataset and try to get the value of the Identity with
adoDataset.fieldbyname('ident').asinteger returns 'Field not found'

Any help would be appreciated.


0
Comment
Question by:alanjbrown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 2000 total points
ID: 12368436
Hi,

Divide that in two separate sql executions:

Insert into Timetran
(casecode, personno, date .........)
Values
(:ccode , :pno, :tdate, ................)

using a TADOQuery or TADOCommand and

select @@IDENTITY as 'Ident'

in your TADODataset

Regards, Geo
0
 
LVL 1

Author Comment

by:alanjbrown
ID: 12368482
Dosn't that leave the posability of the identity being incremented by another user in between the two operations?

regards

Alan
0
 
LVL 17

Expert Comment

by:geobul
ID: 12368528
select @@IDENTITY as 'Ident'
should be
select @@IDENTITY as Ident
I think. And these two components (ADOQuery and ADODataset) should use the same TADOConnection component without closing the connection in between the two calls.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:geobul
ID: 12368552
@@IDENTITY is in the scope of your current session and therefore can't interfere with other users.
0
 
LVL 1

Author Comment

by:alanjbrown
ID: 12368696
Thanks for the rapid response

Alan
0
 
LVL 17

Expert Comment

by:geobul
ID: 12369177
The pleasure was mine :-)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question