Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 30th, 2009, 10:52 AM
Authorized User
 
Join Date: Mar 2009
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default stored procedure returns -1

The Stored Procedures for insert, update and delete return a minus one (-1) versus a count of the number of records affected. The code in SqlArticleProvider uses the -1 to indicate a failure and returns false for update and delete. The SP database action is completed successfully, though.

I'm using SQLExpress 2008. Is there some setup that I'm missing?

Thanks in advance for any help.
Tom
 
Old June 30th, 2009, 02:52 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Are you sure the provider methods are actually returning false?

You would probably have to set a breakpoint to find out if this is happening, as the BLL methods don't actually make any use of the boolean return values.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old June 30th, 2009, 05:21 PM
Authorized User
 
Join Date: Mar 2009
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default

When creating the Stored Procedure for UPDATE, I copied the SET NOCOUNT ON statement from the Insert procedure. This statement inhibits the count of rows affected and returns a minus one.

Page 211 explains about the Nocount statement.

Tom
 
Old July 1st, 2009, 06:46 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
Originally Posted by tdewey View Post
When creating the Stored Procedure for UPDATE, I copied the SET NOCOUNT ON statement from the Insert procedure. This statement inhibits the count of rows affected and returns a minus one.
Yes, exactly. If you SET NOCOUNT ON in the update stored procedure, the stored procedure will always return -1.

That means the UpdateArticle method in SqlArticlesProvider will always return false.

This happens even when the update is successful.

The important thing to remember is that the fact that UpdateArticle returns false has absolutely nothing to do with whether the update operation was successful. You have forced it to always return false because you have SET NOCOUNT ON.

The same thing applies with Insert and Delete. If you SET NOCOUNT ON, then the interger that would normally be returned by executing the query will always be -1.

This is why it is common to SET NOCOUNT ON when doing an insert. When doing an insert, the return value you are interested in is usually the ID of the newly inserted article, not the number of rows affected.

However, it is common to leave the count enabled when doing updates and deletes. When doing updates and deletes, the number of rows affected is important information.

BOTTOM LINE:
  • It is generally okay to SET NOCOUNT ON for inserts if you are returning the ID of the newly inserted item.
  • For updates and deletes, you should not SET NOCOUNT ON. You should let the sproc return the number of rows affected.
Does that make sense?
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
tdewey (July 7th, 2009)
 
Old July 7th, 2009, 01:13 AM
Authorized User
 
Join Date: Mar 2009
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Yes, your explanation makes sense.

Thanks very much.
tom





Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure returns EXPR 1000 EDGiridhar Crystal Reports 1 June 14th, 2007 12:58 PM
Stored Proc that returns a value elygp SQL Server 2000 4 May 9th, 2007 01:05 AM
How are Carriage Returns stored? SQLScott SQL Server 2005 2 December 1st, 2006 04:07 PM
How are Carriage Returns stored? SQLScott SQL Server 2000 3 November 24th, 2006 10:37 AM
Stored Proc returns closed recordset ? xgbnow Pro VB Databases 10 March 26th, 2004 06:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.