Beginner stored proc issue

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to call a sp that inserts a row and returns the id. I take it that I
have to use command vs. reader sqlcleint object to achieve this? How'd I
read the id back if the id is returded via a select at the end of the SP vs.
thru a o/p parameter? Thanks.
 
I made that once like this:

Create Procedure sp_myproc
@name as varchar(100)
as
begin
insert into table (name) values (@name)
select @@identity --assuming that id is identity
end

In your .Net code, you declare a commandType of scalar a get the return of
the stored procedure after execute it.

I hope this helps you.
 
Hi,

How come when I tried to read the sqlCommand sCMD and found it to be -1
after exec and 0 before exec? Thanks.
 
With the example given below, you'd need to return the identity via:

object o = sCMD.ExecuteScalar()

Is that what you're doing?
 
Thanks very much , Brendan and Victor.
--
bic


Brendan Green said:
With the example given below, you'd need to return the identity via:

object o = sCMD.ExecuteScalar()

Is that what you're doing?
 
Back
Top