473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Returning Identity.

I tried the following

Set RS=CN.Execute("INSERT into tableX yada yadayada ; SELECT
SCOPE_IDENTITY()")

Using Profiler, I see the statement go through.
But ASP gives me an error saying RS is not an object.
"Operation is not allowed when the object is closed."

In these lines
if not RS.EOF then
theNewId=RS.Fields(0)
end if

If I run the same query in QueryAnalyzer, I do get a return value.

Am I missing something?

Thanks
Tom
Jul 19 '05 #1
2 1988
You forgot SET NOCOUNT ON. The n row(s) affected message from the INSERT
fools ADO into believing there is an interim resultset. Though, seeing the
rest of the code might reveal other issues as well.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"TomB" <sh*****@hotmailXXX.com> wrote in message
news:Op**************@tk2msftngp13.phx.gbl...
I tried the following

Set RS=CN.Execute("INSERT into tableX yada yadayada ; SELECT
SCOPE_IDENTITY()")

Using Profiler, I see the statement go through.
But ASP gives me an error saying RS is not an object.
"Operation is not allowed when the object is closed."

In these lines
if not RS.EOF then
theNewId=RS.Fields(0)
end if

If I run the same query in QueryAnalyzer, I do get a return value.

Am I missing something?

Thanks
Tom

Jul 19 '05 #2
Very good.

I should have just done a stored procedure.

Thanks
TomB

"Aaron Bertrand - MVP" <aa***@TRASHaspfaq.com> wrote in message
news:uY**************@TK2MSFTNGP10.phx.gbl...
You forgot SET NOCOUNT ON. The n row(s) affected message from the INSERT
fools ADO into believing there is an interim resultset. Though, seeing the rest of the code might reveal other issues as well.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"TomB" <sh*****@hotmailXXX.com> wrote in message
news:Op**************@tk2msftngp13.phx.gbl...
I tried the following

Set RS=CN.Execute("INSERT into tableX yada yadayada ; SELECT
SCOPE_IDENTITY()")

Using Profiler, I see the statement go through.
But ASP gives me an error saying RS is not an object.
"Operation is not allowed when the object is closed."

In these lines
if not RS.EOF then
theNewId=RS.Fields(0)
end if

If I run the same query in QueryAnalyzer, I do get a return value.

Am I missing something?

Thanks
Tom


Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Sergio | last post by:
If I have a private member: void (*func)(void); how can i declare a 'get' function that returns it? I tryed: void (*)()GetFunc() { return func; }
5
by: Eugene | last post by:
I have a table EugeneTest(id_num, fname, minit, lname) where field "id_num" is type IDENTITY and has UNIQUE constraint Let's say 2 user execute this code at the same time: DECLARE @return...
4
by: vassone | last post by:
Dear All, My newly insert GUID is not return from a store procedure. I turned this around and around and can't understand why. The records are inserted but no GUID is returned. I use...
11
by: Steven Blair | last post by:
Hi, I am using ODBC namespace and MySQl 4.1 and have hit this problem a number of times and had to do some nasty coding to get round the problem. I am convinced there is a easier way to do...
1
by: smen | last post by:
hiye, i use sqlcommand.executescalar to insert datainto my table hoping that it will return the table id, but its not :(. can someone uot there tell mehows its done? thanks in advance.
3
by: Tim::.. | last post by:
Can someone please help... I'm kind of new to asp.net and VS.net and need to know how to get the value of a variable in the following funtion into a sub on another aspx page! Can someone please...
3
by: Dan | last post by:
I'm writing a record from an asp.net page to SQL Server. After the insert I'm selecting @@identity to return the ID of the record that I just wrote. It worked fine until I typed a semicolon into...
0
by: Elmo Watson | last post by:
Let's say I have a tableAdapter which uses an Insert sProc -- the last line in the sProc is a Select statement, returning the identity in code, I write something like: Dim myTA as (TableAdapter)...
4
by: scparker | last post by:
Hello, We have a stored procedure that does a basic insert of values. I am then able to retrieve the ID number created for this new record. We are currently using ASP.NET 2.0 and use N-Tier...
2
by: YisMan | last post by:
Hi Everybody, I'd Appreciate anybody who can give me a lead here. I'm trying to run an "Insert" command from my ASP page. The command takes as values some on-page textboxes as well some other...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.