Solved

Can I retrieve all recordsets from a collection?

Posted on 2002-06-14
11
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
11 Comments
 
LVL 143

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 9

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 143

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 9

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 143

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

751 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