Solved

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

Posted on 2008-06-12
4
193 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 25 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

696 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