Solved

Can I retrieve all recordsets from a collection?

Posted on 2002-06-14
11
254 Views
Last Modified: 2008-03-06
hi,

I wonder if it is possible to retrieve all recordsets by looping in a collection. A bit like:

For each rsTest in Recordsets
    ...
Next

I've tried the code above and this one:

for each rsTest  in cnMyConnection.recordsets
     ....
next

But it told me "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another."

What I want to do is a loop that get all my recordsets, close them and set them to nothing automatically.
(I'm maintaining a site where recordsets are not closed explicitly and typing them all will be a very big job!)

Thanks
0
Comment
Question by:FraggleRock
  • 6
  • 3
  • 2
11 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 7077715
if you add all the recordsets at creation into a collection, you can do that:

dim Recordsets 'as collection
set Recordsets = new collection
   
...
recordsets.Add rsData1
...
recordsets.Add rsData2

...


for each rsTest in Recordsets
  rs.Close
  set rs = nothing
next
'this is important !
set Recordsets = nothing


0
 
LVL 1

Author Comment

by:FraggleRock
ID: 7077725
Thanks very much!

That was quick!! :)

Christophe
0
 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 7077766
I will be glad if i am wrong, but give a thought to the following...

According to COM philosophy, as i understand it, the object is cleared from memory when ALL the references to that object are removed.

Now, see what is happening in above code. When you say Recordsets.Add rsData1 is not the 'reference' of rsData1 being copied in the collection?

When you call .close and set rs = nothing in a for next loop, is rsData1 still not hanging around?

Again, i might be wrong, but worth considering.

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Author Comment

by:FraggleRock
ID: 7077768
I have a problem with it.

I've just tried it and I have the following error message:
Error Type:
Microsoft VBScript runtime (0x800A01FA)
Class not defined: 'collection'
/scripts/billing/bllitemisemobile.asp, line 44


Is there something I've forgot?

I am using IIS5 with SQL Server 2000.

Thanks for your help

Christophe
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7077769
You are not wrong, and this is why is have this:
>>'this is important !
>>set Recordsets = nothing

Clearing the recordsets objects will clear also all the last reference to the recordset objects...

CHeers

0
 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 7077775
You cannot have strongly typed variables (such as string, integer, collection, etc.) in ASP.

You can use dictionary instead (Set recordsets = Server.CreateObject("Scripting.Dictionary")), but then you will have change your for next loop as well...
0
 
LVL 1

Author Comment

by:FraggleRock
ID: 7077779
I forgot to put the code:
dim Recordsets
set Recordsets =new collection

And the problems comes when I set the recordsets.

Thanks for your help
Christophe
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7077787
Sorry, forgot that you are in ASP:
set Recordsets = Server.CreateObject("VBA.Collection")

CHeers
0
 
LVL 1

Author Comment

by:FraggleRock
ID: 7077811
angelIII, your solution seems fine on paper but I have the following error with the VBA.Collection:

Server object, ASP 0177 (0x800401F3)
Invalid class string

The server is my local machine and I have Access installed so it should find the object.
Also, I am not sure that the VBA library is installed on our live server...

In the meantime, I'll give a go to the dictionnary option
0
 
LVL 1

Author Comment

by:FraggleRock
ID: 7077852
Well, I'm stuck both ways even if both solutions are good.
Unfortunately, I don't have much time as I am pressed to carry on with other work.

But thanks anyway for your help, I'll carry on looking into it when I'll have a bit of free time.

NitinSontakke, I'll set up a question for you to get 200 points as well, your contribution has been as valuable as angel's one.

Just give me 5 minutes.

Christophe
0
 
LVL 1

Author Comment

by:FraggleRock
ID: 7078059
NitinSontakke, please go to the following question to claim your points:
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=asp&qid=20311655

Thanks,
Christophe
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Update function to validate checkbox is checked 4 74
Need help to rewrite script 3 79
Questions about INCLUDE FILES 2 31
Select case on click 3 13
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question