Solved

Can I retrieve all recordsets from a collection?

Posted on 2002-06-14
11
251 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
Comment Utility
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
Comment Utility
Thanks very much!

That was quick!! :)

Christophe
0
 
LVL 6

Expert Comment

by:Nitin Sontakke
Comment Utility
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
 
LVL 1

Author Comment

by:FraggleRock
Comment Utility
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]
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 6

Expert Comment

by:Nitin Sontakke
Comment Utility
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
Comment Utility
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]
Comment Utility
Sorry, forgot that you are in ASP:
set Recordsets = Server.CreateObject("VBA.Collection")

CHeers
0
 
LVL 1

Author Comment

by:FraggleRock
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now