Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ASP / Database Access / August 2007



Tip: Looking for answers? Try searching our database.

How to rewind a recordset from Cmd.Execute

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
michael sorens - 21 Aug 2007 23:40 GMT
I want to invoke the Execute method of a Command to obtain a record set, then
reuse that record set twice. A rough code outline appears below. It appears
that the record set return from Command.Execute is non-rewindable, however;
upon attempting the second "MoveFirst" I get this error:
"error '80040e18'  Rowset position cannot be restarted."
Is there a straightforward way to make this record set reusable?

==========================
Set Cmd=CreateObject("ADODB.Command")
Cmd.CommandText = sqlText
Set Cmd.ActiveConnection=MyConnection
arParams = Array(IDCustomer, IDUser)
Set rs = Cmd.Execute(,arParams, adCmdText)

<%rs.MoveFirst
Do While Not rs.EOF%>
. . .
<%rs.MoveNext
Loop%>
. . .
<%rs.MoveFirst
Do While Not rs.EOF%>
. . .
<%rs.MoveNext
Loop%>

==========================
Bob Barrows [MVP] - 22 Aug 2007 06:55 GMT
> I want to invoke the Execute method of a Command to obtain a record
> set, then reuse that record set twice.

Silly.
Use GetRows to stuff the data into an array, close your connection and
recordset, and do whatever you want to do with the data.

Remember, the idea is to get into the database, get your data or perform
your tasks, and _immediately get back out of the database_
See http://www.aspfaq.com/show.asp?id=2467 for an example of using GetRows
(and GetString for that matter)

Signature

Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

michael sorens - 22 Aug 2007 17:38 GMT
I agree, it was a rather silly question... my only excuse is that I am still
getting my feet wet and do not yet know my way around the libraries for
ASP/VBScript sufficiently. Your solution is what had immediately come to mind
but I did not quite know where to look to implement it. Thanks for pointing
me to precisely what I needed.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.