jglazer63
asked on
cannot get a value from scope_identity after insert
In ASp i am doing this:
set objrs=objconn.execute("ins ert into cart (title) values ('something');select SCOPE_IDENTITY() as id;")
When I check objrs("ID") it returns blank. Nothing. This works fine access but not in SQL 2000. I find that it seems to have something to do with it being in the second line of the SQL. if I replace the scope_identity() with max(cartid) i get the same thing. So the second line is not returning a value.
Running this in the query analyzer DOES return the value as expected.
Any ideas?
set objrs=objconn.execute("ins
When I check objrs("ID") it returns blank. Nothing. This works fine access but not in SQL 2000. I find that it seems to have something to do with it being in the second line of the SQL. if I replace the scope_identity() with max(cartid) i get the same thing. So the second line is not returning a value.
Running this in the query analyzer DOES return the value as expected.
Any ideas?
Have you tried running this query as a stored procedure? I seem to remember running into this a while back and setting up an SP fixed it.
ASKER
I do not want to do this as a stored procedure. I want to do this entirely with the ADO execute. It needs to be very generic.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also, although I know you say you don't want a proc, but a proc is the BEST thing for DB processing.
That's it -- SET NOCOUNT ON...I knew there was something I was missing. Brandon's right on the money.
ASKER
Perfect. You got it. Thanks!