Solved

Need @@identity in an ASP

Posted on 1998-10-07
4
203 Views
Last Modified: 2010-03-19
I execute a query that reads:
INSERT INTO table (field1, field2) VALUES (2,2)
   SELECT @@identity as ident
If I do that in the Interdev data environment, it returns a table with one column labeled "ident" and the value of the identity field just assigned. When I do the same thing in my ASP then try to access the recordset("ident"), I get "invalid procedure on closed object". Any ideas?
0
Comment
Question by:rickpaul
  • 2
4 Comments
 
LVL 1

Expert Comment

by:abhinavm
ID: 1090448
I think your connection to database is lost due to some reason because i have tried the same code and its working fine.
0
 
LVL 1

Accepted Solution

by:
kdimmock earned 200 total points
ID: 1090449
Try this ...

set nocount on
INSERT INTO table (field1, field2) VALUES (2,2)
   SELECT @@identity as ident
set nocount off
0
 

Author Comment

by:rickpaul
ID: 1090450
Perfect! I wonder if you can tell me where I might have found that in the documentation?
0
 
LVL 1

Expert Comment

by:kdimmock
ID: 1090451
It was one of those things I found by trial and error. I needed to do the same as you and was getting the same problems as you.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

828 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