questions on Asp.net & Sql Server

  • Thread starter Thread starter Edward
  • Start date Start date
E

Edward

hi,

I've one table with an identity column, how can I get its value after
Insert operation.

if I use stored procedure, I can do so like below:
alter procedure sp_.... ( @item out ) {
insert ....
select @@identity )
}

in asp.net , I can add one parameter with direction Output.

so how if I don't use sp?

thanks
 
Change your Stored Proc to

insert ....
select @item = @@identity

This should return the New Identity value. I have not even thought about
not using a SP for this case, but I would try to
1. Explicily OPen the Connection
2. do the Insert
3. Try to execute the Select @@identity statement and check the returned
dattable just to be sure.

The Stored Procedure would be even easier for you.

HTH

Trevor Benedict R
MCSD

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
For SQL Server, you can send 2 statements as a single SQL if you separate
them by a
semi-colon. The first is your Parent update statement the second is:
Select @@Scope_Identity

You can use the older syntax of Select @@identity if needed but be aware
that if a trigger runs on your table you could get back the wrong value.

That is why the newer Scope_Identity should be used.
 
Back
Top