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 July 11th, 2009, 09:52 AM
Authorized User
 
Join Date: Jun 2009
Posts: 32
Thanks: 17
Thanked 0 Times in 0 Posts
Default DataAccess's ExecuteNonQuery() checking the DbType

hi,

I'm not sure if such questions are desired or even appropriate on this forum, since they may appear to be a bit on a nitpicking side, but I'm the type of person that needs to know the exact reasons as to why something was done in particular way , no matter how insignificant it that something may appear

Inside DataAccess base DAL Class's ExecuteNonQuery method, code checks the database type of output parameters and then assigns appropriate default value:

a) Is there a particular reason why we've chosen to set parameters of type Byte and Decimal to minValue instead of 0? Then why we didn't also set parameters of type Int16 to minValue ( instead we assigned them a value of 0 )?


b) Is there a reason why author specifically checked only the following DbType values ( AnsiString, String, Currency, Date, DateTime, Guid ... ), but he didn't check for other DbType values ( like DateTime2, sbyte, UInt16 etc - in cases where parameter was one of these types, parameter was assigned null)? Perhaps parameters are most likely to be one of those types, or is there some other reason?




c)When current context's user name is »sampleeditor«, ExecuteNonQuery returns 1. Is there a reason why method returns 1 and not some other number? Just a convenction or...


thanx
 
Old July 13th, 2009, 05:47 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
Is there a particular reason why we've chosen to set parameters of type Byte and Decimal to minValue instead of 0? Then why we didn't also set parameters of type Int16 to minValue ( instead we assigned them a value of 0 )?
In the case of Byte, it doesn't really make any difference, as the minvalue is in fact 0. For Decimal... honestly, I don't know. I agree it would have made more sense to set it to 0 for the sake of consistency.

Quote:
but he didn't check for other DbType values ( like DateTime2, sbyte, UInt16 etc -
Some of the enum members of DbType (such as DateTime2) didn't even exist at the time the book was written, since they only apply to SQL Server 2008, not 2005.

Quote:
When current context's user name is »sampleeditor«, ExecuteNonQuery returns 1. Is there a reason why method returns 1 and not some other number?
It returns 1 because that is how the provider methods indicate that a database operation was successful (i.e., that the method affected exactly one record):

int ret = ExecuteNonQuery(cmd);
return (ret == 1);


For a SampleEditor, the method returns 1, but does not actually carry out the query. That way, a SampleEditor can use the application without actually altering the database. The ExecuteNonQuery in effect "fakes out" the application into believing these database operations have succeeded, when in fact they are not even being carried out.
__________________
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:
carewithl (July 15th, 2009)
 
Old July 15th, 2009, 10:52 AM
Authorized User
 
Join Date: Jun 2009
Posts: 32
Thanks: 17
Thanked 0 Times in 0 Posts
Default

hi,

Quote:
Originally Posted by Lee Dumond View Post
Some of the enum members of DbType (such as DateTime2) didn't even exist at the time the book was written, since they only apply to SQL Server 2008, not 2005.
So, if the book was written now, it would most likely check all other DbType types also, instead of assigning them a null value?

thanx mate, I really appreciate your help
 
Old July 15th, 2009, 11:04 AM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Quote:
So, if the book was written now, it would most likely check all other DbType types also, instead of assigning them a null value?
I'd say yes, more than likely. However, from a practical standpoint, you only really need to handle the data types that the application actually uses.
__________________
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:
carewithl (July 16th, 2009)
 
Old July 16th, 2009, 09:13 AM
Authorized User
 
Join Date: Jun 2009
Posts: 32
Thanks: 17
Thanked 0 Times in 0 Posts
Default

thanx mate. Can't tell you how I appreciate your help

cheers





Similar Threads
Thread Thread Starter Forum Replies Last Post
ExecuteNonQuery not giving proper result Lalit Pradhan ASP.NET 2.0 Professional 6 July 24th, 2008 02:00 AM
Expaning on ExecuteNonQuery () in DataAccess class kalel_4444 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 July 21st, 2008 03:52 PM
VB.NET ExecuteNonQuery() command Lofa SQL Server 2000 1 September 20th, 2005 10:03 AM
OleDbCommand.ExecuteNonQuery(); kaz VS.NET 2002/2003 1 December 7th, 2003 04:29 PM





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