Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > BOOK: Beginning ASP 3.0
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP 3.0 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 November 11th, 2003, 01:22 AM
Registered User
 
Join Date: Oct 2003
Location: Charleston, SC, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Errors in Code; Chapter 14, pages 566-567

I need to know if an error exists within the code on pages 566 - 567. The example "Command.asp" as given in the book, does not return the records in a numeric order. When displayed in IE 6.0 the order of the records are not correct. For example, after record 14 is displayed, then records 27, 32, and 40 follow before record 15 is displayed. Could this be a pointer problem?? In looking over the code, I do not see anything that would move the pointer 13 records, and then 5 records and finally 8 records before returning the pointer back 25 records. Am I missing something?? Has anybody had this problem?? If so, what did you do to correct? Any assistance will be greatly appreciated.

ou812
  #2 (permalink)  
Old June 18th, 2004, 03:21 PM
Authorized User
 
Join Date: Jun 2004
Location: Belfast, , United Kingdom.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I also have this problem using IE6, though in my case the offending rows are 251 to 256 which seem to come in around 90. I have had this problem in other areas such as moving.asp in Chapter 12. Can anybody offer any explanation?
  #3 (permalink)  
Old June 19th, 2004, 03:52 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

I don't have the book, so I can only take a guess. Are you using a SELECT statement without an ORDER BY clause? E.g.

SELECT ID, Column1, Column2 FROM MyTable?

If you don't specify the ORDER BY, the database will determine the order. This is based on internal workings of the database, so the order of the records is unpredictable.

If that doesn't help, can you post the code?

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Doppelganger by Curve (Track 4 from the album: Doppelganger) What's This?
  #4 (permalink)  
Old June 19th, 2004, 07:14 AM
Authorized User
 
Join Date: Jun 2004
Location: Belfast, , United Kingdom.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Results see problem at 70 only posted to 100 rest of the records goes to EOF ommitting of course 251-256 which have appeared after 70. Code is from Wrox site. Thanks for your Time
1: Bullets Over Broadway (1994)
2: River Runs Through It, A (1992)
3: Tombstone (1993)
4: Alice (1990)
5: Carlito's Way (1993)
6: Akira Kurosawa's Dreams (1990)
7: Mermaids (1990)
8: Bewegte Mann, Der (1994)
9: Exotica (1994)
10: Red Rock West (1992)
11: Chaplin (1992)
12: Orlando (1993)
13: Fearless (1993)
14: Joy Luck Club, The (1993)
15: Immortal Beloved (1994)
16: Threesome (1994)
17: Glengarry Glen Ross (1992)
18: Jungle Fever (1991)
19: Little Man Tate (1991)
20: Internal Affairs (1990)
21: Single White Female (1992)
22: Trust (1991)
23: Ju Dou (1990) (FL:AA/1991)
24: C'est Arrive Pres de Chez Vous (1992)
25: Dahong Denglong Gaogao Gua (1991) (FL:AAN)
26: Cyrano de Bergerac (1990) (FL:AAN)
27: Manhattan Murder Mystery (1993)
28: El Mariachi (1992)
29: Once Were Warriors (1994)
30: Priest (1994)
31: Usual Suspects, The (1995)
32: Smoke (1995) (SBB)
33: Night on Earth (1991)
34: Don Juan DeMarco and the Centerfold (1995)
35: Miller's Crossing (1990)
36: Muriel's Wedding (1994)
37: Pump Up the Volume (1991)
38: Kalifornia (1993)
39: Benny & Joon (1993)
40: Husbands and Wives (1992)
41: Hamlet (1990)
42: Quick Change (1990)
43: Memphis Belle (1990)
44: Conquest of Paradise (1992)
45: Naked (1993)
46: Bridges of Madison County, The (1995)
47: Six Degrees of Separation (1993)
48: Bawang Bie Ji (1993) (FL:AAN) (GPC) (FL:GG)
49: In the Line of Fire (1993)
50: Peter's Friends (1992)
51: Freshman, The (1990)
52: Hard Way, The (1991)
53: Heavenly Creatures (1994)
54: Hoop Dreams (1994)
55: Seven (1995)
56: Shallow Grave (1994)
57: French Kiss (1995)
58: Wrong Trousers, The (1993)
59: Braindead (1992)
60: Podwojne zycie Weroniki (1991)
61: Clerks (1994)
62: Braveheart (1995)
63: Apollo 13 (1995)
64: Reservoir Dogs (1992)
65: Trzy kolory: Czerwony (1994)
66: Schindler's List (1993) (D:GG) (AA) (GuldbaggeN)
67: Pulp Fiction (1994)
68: Shawshank Redemption, The (1994) (AAN)
69: Yinshi Nan Nu (1994) (FL:AAN) (FL:GGN)
70: Short Cuts (1993) (Guldbagge)
251: Addams Family, The (1991)
252: Kindergarten Cop (1990)
253: Robin Hood: Prince of Thieves (1991)
254: Back to the Future Part III (1990)
255: Paper, The (1994)
256: Housesitter (1992)
71: Hard-Boiled (1992)
72: Walk in the Clouds, A (1995)
73: Under Siege 2: Dark Territory (1995)
74: Mortal Kombat (1995)
75: Legends of the Fall (1994) (D:GGN)
76: Crow, The (1994)
77: Natural Born Killers (1994)
78: In the Mouth of Madness (1995)
79: Piano, The (1993) (GPC) (D:GGN) (AAN)
80: Forrest Gump (1994) (AA) (D:GG) (GuldbaggeN)
81: Rosencrantz and Guildenstern Are Dead (1990)
82: Trzy kolory: Niebieski (1993)
83: Malcolm X (1992)
84: Nightmare Before Christmas, The (1993)
85: Trzy kolory: Bialy (1994)
86: Age of Innocence, The (1993) (D:GGN)
87: Dead Again (1991)
88: Aladdin (1992)
89: Jurassic Park (1993)
90: Clueless (1995)
91: Strictly Ballroom (1992) (C:GGN)
92: Shadowlands (1993)
93: Hudsucker Proxy, The (1994)
94: Lion King, The (1994) (C:GG)
95: Nobody's Fool (1994)
96: Amateur (1994)
97: Hsi Yen (1993) (FL:AAN) (FL:GGN)
98: Como Agua Para Chocolate (1992)
99: Crimson Tide (1995)
100: Nikita (1990)
<%
Option Explicit
Dim strConnect %>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>ADO Command Object</title>
</head>
<body>
<%

Dim objCommand, objRS
Set objCommand = Server.CreateObject("ADODB.Command")

objCommand.ActiveConnection = strConnect
objCommand.CommandText = "AllMovies"
objCommand.CommandType = adCmdTable

Set objRS = objCommand.Execute
Set objCommand = Nothing

While Not objRS.EOF
  Response.Write objRS("TitleID") & ": " & objRS("Title") & "<BR>"
    objRS.MoveNext
Wend
objRS.Close
Set objRS = Nothing

 %>


</body>
</html>
  #5 (permalink)  
Old June 19th, 2004, 08:22 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Yeah, that's what I thought. You're displaying the entire table, leaving it up to the database to "sort" the data.

Try this instead:
Code:
objCommand.CommandText = "SELECT AllMovies.TitleID, AllMovies.Title FROM AllMovies ORDER BY " & _
      "AllMovies.TitleID      "
objCommand.CommandType = adCmdText
This way, you create an explicit SQL query so you can use an ORDER BY clause to order the data. In this case, it's ordered by TitleID, but you can change that to Title, or to any other column in the database table.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Dreams Are Like Water by This Mortal Coil (Track 19 from the album: Blood) What's This?
  #6 (permalink)  
Old June 19th, 2004, 09:12 AM
Authorized User
 
Join Date: Jun 2004
Location: Belfast, , United Kingdom.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for thatImar, Worked fine as you suggested. Actually, I was pretty comfortable with SQL and I understand the interrelationship between the command object and the RecordSet object, but I was a little confused as to the failure of the Recordset approach. The RS approach must be sorting on some form of internal order - even if it is only based on the sequence upon which records were added to the table. Looking at the table in Access with no form of filtering or ordering gives an uninterrupted sequency from 1-330! Yet this is not the result returned by the recordset method. What is going on? As you have illustrated - when you explicitly state the sort using SQL there is no problem, but it does rather defeat the purpose of the simple RS method. My real interest in this issue was the other problem that you are looking for me. The large dataset issue. I wondered if some problem in the internal sorting was causing the problem. Anyway, if you have any explanation for why the recordset object doesn't work quite as expected I would be interested, but otherwise I will just use the more explicit command object. Thanks for your efforts on this.

Basil
  #7 (permalink)  
Old June 19th, 2004, 09:21 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Like I said, I think the database internally keeps track of the records. Maybe it orders them in the way they were added, or, for example, by an index on a column. If, for example, you'd index a specific column, you'd find that all of a sudden the data gets sorted by that column (that happens in SQL anyway). Whatever the logic behind it, the official sort order is "undetermined". This means that there is no guaranteed and / or documented order for the data. You get it in the order that the database pleases.... ;) So, if you want to order it, you have to order it yourself.

If you want to use the adCmdTable way of opening a table, look at the Sort property.
Personally, I rather use a direct SQL statement than opening the entire table, as opening the entire table is slower (you're sending all columns and records over the wire, depending on the type of recordset / cursor you're using). That's why I suggested the SQL statement rather than the Sort property.

Cheers,


Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Without A Face (Live) by Rage Against The Machine (Track 8 from the album: Live & Rare) What's This?
  #8 (permalink)  
Old June 19th, 2004, 01:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes, Imar is right, on using sql statement than opening the entire table, that really slows down the process. As one would want to use only 2 columns from the table, but would open the entire table (either using sql statement with a "SELECT *" or adCmdTable) which populates the recordset with all the data from the table. This is not recommended, especially when processing with more number of rows. So that way using a select statement to retrieve the needed columns is the right approach.

Quote:
quote:Whatever the logic behind it, the official sort order is "undetermined".
On the Index thing, I came across in a site something related to this.
Auto Index
If you open up Access and select Tools ... Options and then select the Tables / Queries tag you will find a field called

Auto Index on Import/Create:

If you have any fields in your database with these prefixes or suffixes, you will find that you have indexes on the field whether you like it or not. You may as well clear the "Auto Index on Import/Create" text box on this tab as this is a very unnecessary feature.

The standard keys featured here are

ID;Key;code;num

So look out for those fields cause your database will be bigger and slower than you think.

On SQL server when a column is indexed of clustered type, that physiscally sorts the rows in the table by that column, but creating anyother index after that would not sort the rows physically on table, as only one clustered index is allowed per table and all others can be non-clustered. If the query is based on clustered indexed column, then the resulting recordset would contain rows in that order, otherwise, I think the recordset would contain the rows in the order it was input.

Hope that helps.
Cheers!

_________________________
-Vijay G
Strive for Perfection
  #9 (permalink)  
Old June 19th, 2004, 04:46 PM
Authorized User
 
Join Date: Jun 2004
Location: Belfast, , United Kingdom.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks both for your reply. I agree with both of you. In the production environment we use MSSQL 2000. I just wanted to use Access for demonstrations on laptops that sort of thing. I wasn't that interested in the problem when I first saw it as I rationalised it in the way that you have... but when I saw the original posting my intellectual curosity was aroused. How can it happen that a simple database which will have been downloaded from the Wrox site by lots of people and works for them, doesn't work for me. The code is correct, the database is correct and at least one other person had the problem. It's just academic really, I can't work out how it happened. If it was a problem with indexing it would be a problem for everybody not just me. Perhaps it is the method in which the file is unzipped or some other setting. I have updated MDAC from 2.5 to 2.8 but this has had no effect. This is not crucial but I just wondered if there were any plausible reasons as to why it works for some and not others. Everything about this is simple and standard!
  #10 (permalink)  
Old June 20th, 2004, 04:53 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

I agree with you that it is strange. You'd expect the same file to behave the same way on multiple systems. But then again, I guess that's what they mean with "undetermined"...... ;)

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Paisley Park by Prince and the Revolution (Track 2 from the album: Around The World In A Day) What's This?
 


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
Chapter 14 Code Error? pherank BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 4th, 2008 09:05 PM
CH 14 Pages 749-753 Compile Errors Razzy The Pug BOOK: Ivor Horton's Beginning Visual C++ 2005 1 March 28th, 2008 10:20 AM
Problem with code on Chapter 14 aargyri BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 3 June 6th, 2006 03:37 PM
Chapter 14 Code example in Oracle DB theinscrutable BOOK: Professional Jakarta Struts 0 January 10th, 2005 01:31 PM



All times are GMT -4. The time now is 05:07 AM.


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