hmcgeehan
asked on
Returned value from stored procedure - where is it coming from?
Hi
I'm updating a website and I'm looking at code that I didn't write :)
I see code that inserts data into a table in a database.
It's fairly straightforward.
The table 'news' has a primary key which is an identity - 'news_rid'
In the Visual Basic.Net website I see this line.
_newsid = Convert.ToInt32(SqlHelper. ExecuteSca lar(System .Configura tion.Confi gurationMa nager.AppS ettings("C onnectionS tring"), "usp_News_Add", contentid, _homepageflag, UserName))
I assumed that this inserted a row and assigned the newly created 'news_rid' into _newsid
Is it right to think that?
If so how does the stored procedure return the news_rid?
I don't see an output parameter in the stored procedure (below)
Thanks!
I'm updating a website and I'm looking at code that I didn't write :)
I see code that inserts data into a table in a database.
It's fairly straightforward.
The table 'news' has a primary key which is an identity - 'news_rid'
In the Visual Basic.Net website I see this line.
_newsid = Convert.ToInt32(SqlHelper.
I assumed that this inserted a row and assigned the newly created 'news_rid' into _newsid
Is it right to think that?
If so how does the stored procedure return the news_rid?
I don't see an output parameter in the stored procedure (below)
Thanks!
ALTER PROCEDURE [dbo].[usp_News_Add]
(
@contentid int,
@homepageflag bit,
@updatedby nvarchar(55)
)
AS
DECLARE @Error int
DECLARE @lineID int
DECLARE @ptrval binary(16)
declare @updatedid int
select @updatedid= users_rid from users where users_login = @updatedby
SET @Error = @@ERROR
IF @Error != 0 GOTO ERROR_HANDLER
BEGIN TRANSACTION
Insert INTO news
(
content_rid,
news_homepage,
UpdatedBy,
deleted_flag
)
Values(
@contentid,
@homepageflag,
@updatedid,
0
)
COMMIT TRANSACTION
SELECT @@identity AS ID
ERROR_HANDLER:
IF @@TRANCOUNT != 0 ROLLBACK TRANSACTION
RETURN @Error
you will get value as table which contains last inserted row's ID
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Easy when you know how!
Thanks so much!
Thanks so much!
ASKER
HttpContext.Current.Respon
_newsid = Convert.ToInt32(SqlHelper.
HttpContext.Current.Respon
HttpContext.Current.Respon
and got this ..
[0]
[9]
so it is assigning the value I just don't understand how :)