Wrox Programmer Forums
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 19th, 2005, 10:50 AM
Authorized User
 
Join Date: Dec 2004
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to datagram Send a message via AIM to datagram
Default @@IDENTITY Problem

In SQL, the command would be:

DECLARE @ID AS INT
SET @ID = @@Identity
INSERT INTO tbl_lmedata_equipment
(lmedata_id)
VALUES
(@id)


In ASP, VB.NET, what is the command for this? Ive tried almost everything. Visual Basic doesnt pick up the @@Identity as being anything. How do I get the auto increment variable without using the @@ Identity?
Thank you!


 
Old May 19th, 2005, 01:09 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

@@IDENTITY will work only when you are in the same connection that inserted a record. You can't make to separate calls and get it to work. Instead, build a query statement that contains both:

INSERT INTO .... ; SELECT @@IDENTITY;

Then run the query with .ExecuteScalar() and you can get the identity for the new row.

-Peter
 
Old May 19th, 2005, 01:34 PM
Authorized User
 
Join Date: Dec 2004
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to datagram Send a message via AIM to datagram
Default

Wow, thank you so much!! I was using the ExecuteNonQuery, it wasnt working!! ExecuteScalar works great, Thank you again so much!
:):):):):):):)






Similar Threads
Thread Thread Starter Forum Replies Last Post
@@IDENTITY use... neo_jakey Classic ASP Professional 1 May 3rd, 2008 06:47 AM
IDENTITY Field ricespn SQL Server 2000 4 November 2nd, 2007 11:40 PM
Problem in geting the @@Identity Value janamca_thanan Biztalk 0 December 17th, 2006 09:31 AM
what does identity do amruthhr SQL Server 2000 2 January 6th, 2005 09:45 AM
Identity soccers_guy10 SQL Server 2000 3 September 2nd, 2003 07:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.