Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8
This is the forum to discuss the Wrox book Beginning ASP.NET 2.0 by Chris Hart, John Kauffman, David Sussman, Chris Ullman; ISBN: 9780764588501
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 28th, 2006, 06:15 PM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Errata - Chapter 9, Page 322, C#

There are a couple of problems with the example on this page. The first one isn't really a code bug, but a logic bug:
Code:
while (rdr.Read())
        {
            goalsFor += Convert.ToInt32(rdr["GoalsFor"]);
            goalsAgainst += Convert.ToInt32(rdr["GoalsAgainst"]);

            if (goalsFor > goalsAgainst)
                wins++;
            else if (goalsFor < goalsAgainst)
                losses++;
            else
                draws++;
        }
Checking for wins and losses this way doesn't make any sense, because the code is evaluating the cumulative goal totals. It should be comparing the goalsFor and goalsAgainst for each individual game:
Code:
while (rdr.Read())
        {
            int thisGameGoalsFor = Convert.ToInt32(rdr["GoalsFor"]);
            int thisGameGoalsAgainst = Convert.ToInt32(rdr["GoalsAgainst"]);

            if (thisGameGoalsFor > thisGameGoalsAgainst)
                wins++;
            else if (thisGameGoalsFor < thisGameGoalsAgainst)
                losses++;
            else
                draws++;

            goalsFor += thisGameGoalsFor;
            goalsAgainst += thisGameGoalsAgainst;
        }
The second problem is this line:
Code:
winRatio = Convert.ToInt32(wins / losses * 10);
Because the wins and losses variables are integers, this expression will always evaluate to zero if there are more losses than wins. In order for this work, you have to do a conversion to a floating point number. There's probably a more elegant way to do this, but here's what I did to get it to work:
Code:
double winPercent = wins * 1.0 / losses;
winRatio = Convert.ToInt32(winPercent * 10);
Finally, there's a problem with the downloaded code in Begin\Chapter09. If you look at the data in the Fixtures table in WroxUnited.mdf, you'll see that there are NULL values in the GoalsFor and GoalsAgainst in the tenth record. You'll have to either delete this record or enter numbers for these fields - otherwise, you'll get a runtime error.
  #2 (permalink)  
Old August 30th, 2006, 02:59 AM
Authorized User
 
Join Date: Dec 2003
Location: , , United Kingdom.
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

Rob

Right on both counts - these are logic errors. The ration problem is simply explained - the whole concept of WroxUnited was that they virtually never won a game, so I never actually tested with more wins than losses. This shows an important point about application testing, in that you should always test with a variety of values, even ones you don't expect.

Dave

  #3 (permalink)  
Old September 8th, 2006, 02:08 PM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could you explain why this part

"Finally, there's a problem with the downloaded code in Begin\Chapter09. If you look at the data in the Fixtures table in WroxUnited.mdf, you'll see that there are NULL values in the GoalsFor and GoalsAgainst in the tenth record. You'll have to either delete this record or enter numbers for these fields - otherwise, you'll get a runtime error."

is not in the Errata as something one needs to do so that you do not get this "Object cannot be cast from DBNull to other types. " when attempting to run the page?

  #4 (permalink)  
Old October 25th, 2006, 04:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Banbury, , United Kingdom.
Posts: 105
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to DanM
Default

tbroom,
You're right of course. My best guess as to why this happened is that one of the authors added an extra row to that table by mistake. It should be deleted.

Wrox United never have the energy to play ten games in a season.

Dan

Dan Maharry
Read the feed at http://feeds.feedburner.com/dansarchive
  #5 (permalink)  
Old November 23rd, 2007, 08:28 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How do I delete this 10th record so I can get rid of the runtime error??

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Errata - Chapter 9, Page 337, C# RobC BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 2 August 30th, 2006 08:17 AM
Errata - Chapter 9, Page 336, C# RobC BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 August 30th, 2006 03:06 AM
Errata - Chapter 9, Page 299, C# RobC BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 August 30th, 2006 03:03 AM
Errata - Chapter 9, Page 296, C# RobC BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 August 30th, 2006 02:51 AM



All times are GMT -4. The time now is 03:33 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.