retrieve primary key after insert statement (using ADO / SQL Server 2000)

retrieve primary key after insert statement (using ADO / SQL Server 2000)

Post by Mike Maill » Fri, 07 Mar 2003 06:03:08



Hi,

I'm wondering how to retrieve the primary key (an autonumber) from a
table immediately after a new record has been inserted.  I'm using VB
6.0 / ADO / SQL Server 2000.

Cheers,

Mike.

 
 
 

retrieve primary key after insert statement (using ADO / SQL Server 2000)

Post by Chris Barbe » Fri, 07 Mar 2003 17:58:57


http://www.kamath.com/tutorials/tut007_identity.asp

Does anybody ever search Google first? I entered the subject line of this post and got this.

Chris.

Hi,

I'm wondering how to retrieve the primary key (an autonumber) from a
table immediately after a new record has been inserted.  I'm using VB
6.0 / ADO / SQL Server 2000.

Cheers,

Mike.

 
 
 

retrieve primary key after insert statement (using ADO / SQL Server 2000)

Post by Jason Keat » Fri, 07 Mar 2003 22:22:24



Quote:> Hi,

> I'm wondering how to retrieve the primary key (an autonumber) from a
> table immediately after a new record has been inserted.  I'm using VB
> 6.0 / ADO / SQL Server 2000.

> Cheers,

> Mike.

Mike,


using your connection object, cnn:

Set rst = cnn.Execute(sSQL, , adCmdText).NextRecordset

then retrieve the primary key using

lNewID = rst(0).Value

before closing the recordset, rst.

HTH

 
 
 

retrieve primary key after insert statement (using ADO / SQL Server 2000)

Post by Mayrmonte System » Sat, 08 Mar 2003 09:40:13


Chris,
Just thought you would like to know your note made a difference. I had
a query question and before posting I did exactly what you
said...Googled the heading as I would have sent it...guess
what...found the answer...WONDERFUL LIFE!!

John Lee

On Thu, 6 Mar 2003 08:58:57 -0000, "Chris Barber"


>http://www.kamath.com/tutorials/tut007_identity.asp

>Does anybody ever search Google first? I entered the subject line of this post and got this.

>Chris.


>Hi,

>I'm wondering how to retrieve the primary key (an autonumber) from a
>table immediately after a new record has been inserted.  I'm using VB
>6.0 / ADO / SQL Server 2000.

>Cheers,

>Mike.

 
 
 

retrieve primary key after insert statement (using ADO / SQL Server 2000)

Post by Chris Barbe » Sun, 09 Mar 2003 09:02:15


Thanks.

I often find myself just posting the top couple of relevant (I check them out obviously) Google responses since
something that's already been thought about and presented on the web can often be better than my trying to explain
something.
Just so happens I had the same issue as this thread myself a couple of months back :)
Then again, if everyone did that (checked Google) then there would be no group - LoL!

Chris.

Chris,
Just thought you would like to know your note made a difference. I had
a query question and before posting I did exactly what you
said...Googled the heading as I would have sent it...guess
what...found the answer...WONDERFUL LIFE!!

John Lee

On Thu, 6 Mar 2003 08:58:57 -0000, "Chris Barber"


>http://www.kamath.com/tutorials/tut007_identity.asp

>Does anybody ever search Google first? I entered the subject line of this post and got this.

>Chris.


>Hi,

>I'm wondering how to retrieve the primary key (an autonumber) from a
>table immediately after a new record has been inserted.  I'm using VB
>6.0 / ADO / SQL Server 2000.

>Cheers,

>Mike.