I'm trying to use a store procedure to add an item into the database and retrieve the id of such item within and output parameter but this is not happening.
The item is added into the db but the output param is not modified.
Here is the code:
SP
CREATE procedure dbo.AddItem
(
@.Desc nvarchar(100),
@.intItemID int output
)
as
insert into RR_Item (
desc
)
values (
@.Desc
)
select @.intItemID = SCOPE_IDENTITY()
GO
I have tried in the last line of the SP
select @.intItemID = SCOPE_IDENTITY()
select @.intItemID = @.@.IDENTITY
select @.intItemID = max(itemid) from RR_Item
but nothing seems to work.
I'm calling the store procedure as follows from asp.net:
Dim intItemIDAsNew SqlParameter("@.intItemID", SqlDbType.Int)
intItemID.Direction = ParameterDirection.Output
SqlHelper.ExecuteDataset(objConn.ConnectionString,"AddItem", desc, intItemID)
MsgBox(intItemID.Value.ToString)
Any help would be appreciated.
Thanks
(1) Use SCOPE_IDENTITY().
(2) check the 2nd portion ofthis articleto retrieve the OUTPUT value.
No comments:
Post a Comment