Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Count(*)
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

kolucoms6
Average Member

845 Posts

Posted - 05 May 2007 :  16:23:41  Show Profile
sql = "SELECT Count(*) as RCount FROM ABC"
RS.Open sql, session("cn")
RS.Filter="Sponsored=1"
SponCount=RS("RCount")

Above code doesnt work.It says that

ADODB.Recordset error '800a0cc1'

Item cannot be found in the collection corresponding to the requested name or ordinal.

Whereas I have a column named "Sponsored".

Is it by any chance related with Count(*) and Filter ??

Edited by - kolucoms6 on 05 May 2007 16:24:09

pdrg
Support Moderator

United Kingdom
2897 Posts

Posted - 05 May 2007 :  16:55:17  Show Profile  Send pdrg a Yahoo! Message
Your select will return a single value (the result of count(*)) as a single row, single column recordset, with no field 'sponsored' - I'm a bit rusty but I think that's what's going on...
Go to Top of Page

kolucoms6
Average Member

845 Posts

Posted - 05 May 2007 :  17:01:59  Show Profile

Any way to filter it , but not within query ?
Go to Top of Page

pdrg
Support Moderator

United Kingdom
2897 Posts

Posted - 05 May 2007 :  17:24:21  Show Profile  Send pdrg a Yahoo! Message
Maybe something like

sql = "SELECT <primary key>, [Sponsored] FROM [ABC]"
RS.Open sql, session("cn")
RS.Filter="Sponsored=1"
SponCount=RS.rowcount()

You'll have to check the syntax, but something like that ought to do it (although less efficient than doing it in the SQL)

Also, I don't like the idea of keeping a connection object inside the session object, can't remember why, but I remember it was bad form, certainly back in the early days...
Go to Top of Page

kolucoms6
Average Member

845 Posts

Posted - 05 May 2007 :  17:39:10  Show Profile

Is it better to open a diffrent recordset everytime and get the total count with different where clause ?

OR

Use a query like this :

sql = "SELECT <primary key>, [Sponsored],[Col2],[Col3] FROM [ABC]"

and then running Filter , RS.Filter with filter value??



I guess SECOND one...
Go to Top of Page

pdrg
Support Moderator

United Kingdom
2897 Posts

Posted - 05 May 2007 :  17:53:14  Show Profile  Send pdrg a Yahoo! Message
The high-cost item is the retrieval of the recordset from the db, so get the data once then use your rs.filters is almost certainly quicker once you have the data.

Hope it helps :)
Go to Top of Page

kolucoms6
Average Member

845 Posts

Posted - 05 May 2007 :  17:55:08  Show Profile
Thanks a lot for very quick response.
Go to Top of Page

kolucoms6
Average Member

845 Posts

Posted - 05 May 2007 :  17:57:40  Show Profile
Last quick question :

How to "clear" the filter after assigning it ?
Go to Top of Page

pdrg
Support Moderator

United Kingdom
2897 Posts

Posted - 05 May 2007 :  19:59:31  Show Profile  Send pdrg a Yahoo! Message
Don't know the official line, may be explained on msdn.microsoft.com or try .filter=""!

P
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.33 seconds. Powered By: Snitz Forums 2000 Version 3.4.07