Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Returned value from stored procedure - where is it coming from?

Posted on 2008-06-12
4
Medium Priority
?
203 Views
Last Modified: 2010-04-23
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.ExecuteScalar(System.Configuration.ConfigurationManager.AppSettings("ConnectionString"), "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!
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

Open in new window

0
Comment
Question by:hmcgeehan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:hmcgeehan
ID: 21767113
Just to help I did this


                HttpContext.Current.Response.Write("[" & _newsid & "]<br>")
                _newsid = Convert.ToInt32(SqlHelper.ExecuteScalar(System.Configuration.ConfigurationManager.AppSettings("ConnectionString"), "usp_News_Add", contentid, _homepageflag, UserName))
                HttpContext.Current.Response.Write("[" & _newsid & "]<br>")
                HttpContext.Current.Response.End()

and got this ..

[0]
[9]

so it is assigning the value I just don't understand how :)
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 21767137
you will get value as table which contains last inserted row's ID

0
 
LVL 12

Accepted Solution

by:
renjurdevan earned 100 total points
ID: 21767144
ExecuteScalar method will return @@identity value! ie, last inserted row's identity value!
0
 

Author Closing Comment

by:hmcgeehan
ID: 31466462
Easy when you know how!

Thanks so much!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question