Question

RecordSet in ASP

Asked by: Madhu_28

Hello all,
 Iam looping through a recordset in ASP to create a table
 However when in a current record in the loop is there a way I can get a field value from the next record without moving to the next record in the recordset? Note: Iam not using the GetRows method. Iam looping thru the recordset directly.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2002-02-22 at 11:56:11ID20270005
Tags

asp

,

field

,

get

,

recordset

Topic

Active Server Pages (ASP)

Participating Experts
8
Points
75
Comments
17

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Global Recordset in ASP
    I've a recordset in my page(ASP). It is declared in the If part, I'm not able to access it in the else. What must be done to get it there? If X=y then dim db db = ... set rs = db.open xyz ... else rs.movenext !!Error here in rs undefined end if
  2. getrow ?
    when i using getrow in asp to return recordset array. i have retrieve the data according the index. is that a way in asp so i can return data in something associative array, which with field name and data.
  3. OLEDB and Getrows
    Both 4GuysFromRolla and Charles Carroll recommend using OLEDB instead of ODBC and a DSNless connection. Carroll also recommends using GetRows method to grab all the data at once and then parse them. In his example for GetRows, however, Carroll uses DSN connection! Being ne...
  4. Getrows limitation
    Hi all, my stored procedure return me a recordset which select 2 columns of datatype "Text" when i use getrows to store it into an array and later try to display it out. I found that one of the columns never got displayed. I know that there is no problem...
  5. Loop thru recordset items
    I have a series of stored procedures in a oracle DB that i am outputting to an asp page. It comes in the format: Name item1, item2, item3 etc..... What i want to achieve is that for each person listed it will output the results in a separate table.... One way to achieve...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: thunderchickenPosted on 2002-02-22 at 11:58:57ID: 6819775

just a rs.movenext

then a rs.moveprevious

 

by: Madhu_28Posted on 2002-02-22 at 12:20:57ID: 6819823

Thunder chicken, It doesn't work because in a loop the recordset will not allow a moveprevious.

 

by: thunderchickenPosted on 2002-02-22 at 12:27:16ID: 6819838

This will work as long as you don't have adOpenForwardOnly set with your cursor.  Try adOpenDynamic

 

by: rupertsPosted on 2002-02-22 at 12:30:55ID: 6819844

this because you are using a forward only cursor.

You have two options.
(i)
do until rs.eof
load the current record in to some variables
Move to the next record
Compare them or what ever and produce your output
loop

(ii) Change the cursor type to adDynamic

 

by: rupertsPosted on 2002-02-22 at 12:34:29ID: 6819856

great minds think alike.

rs.cursorlocation = 2 'adUseServer
rs.cursortype = 2 'adOpenDynamic

 

by: ketapillarPosted on 2002-02-22 at 22:44:17ID: 6820673

or use "adOpenStatic" I read somewhere that it's faster to go through than "adOpenStatic"

just my 2?

 

by: Jon_RaymondPosted on 2002-02-22 at 23:31:19ID: 6820701

Another option is to put the recordset into an array, which is usually best for this type of operation.  Although, ADO has the capabilty of allowing you to disconnect the recordset and move through locally.  I assume you need to use a client cursor (adUseClient) and adOpenStatic.  adOpenDynamic is for manipulating records while staying connected so that your recordset always is updated with any server changes.  Use an array:
Dim iRow
Dim ary()
iRow = 0
With rs
  While not .EOF
    iRow=iRow+1
    ary("Field1",iRow)=rs("Field1"}
    ary("Field2",iRow)=rs("Field2")
    .Movenext
  Wend
End With

' now play with it

If ary(2,"Field1")=ary(1,"Field1") Then
  MSGBOX "See I was Right"
End If
       

 

by: CJ_SPosted on 2002-02-23 at 04:29:47ID: 6820833

Jon_Raymond,
 putting the same information already available into another object is usually a bad practice.

 

by: Jon_RaymondPosted on 2002-02-23 at 10:26:44ID: 6821182

If you close and destroy the recordset after filling the array, then you are only using one object at a time.  The recordset is useful for retriveing the data. The array is useful for comparing rows of data.  But, neither one is good for both operations.  Overall, this would use the least memory overhead,especially if the recordset is large.  A dynamic cursor is especially resource intensive and with multiple users will create a potential for record lockups, and system lockups due to memory overrun.  With ASP you have to think in terms of multiple users, hundreds or thousands, hitting the server.  Any resource intensiveoperation is multiplied by the number of users involved.

 

by: acperkinsPosted on 2002-02-24 at 17:38:19ID: 6823468

Jon_Raymond

You are basically duplicating the functionality of ADO's GetRows method.

Anthony

 

by: Jon_RaymondPosted on 2002-02-25 at 13:30:41ID: 6825828

You're missing my main point.  There is no need to stay connected and use a dynamic recordset to compare rows of data.  When you do that you use the overhead associated with maintaining a live link to the database.  It is best to disconnect after retrieving the data and then do the comparison operation.  If you do this with an array you also don't need the overhead with maintaing an ADO recordset.  So, you use ADO to get the data, and that's it.  That's what ADO is good for.  There's no need for GETROWS to get a few rows at a time.  But there is a need to compare rows.  The recordet object is not the best one to use to compare records.  But the array is.  It is also posible to disconnect the recordset and manipulate the recordset as a stand alone object.  That might be a second preference.  But, I doubt you can get better performance for this operation than by using an array.

 

by: acperkinsPosted on 2002-02-25 at 22:42:13ID: 6826720

You may want to take a look at the GetRows method: Using the default parameters will populate an array with the whole recordset.  So yes, if you chose to do so, you can:
1 Open the recordset
2 Fill an array with a call to GetRows
3 Close the recordset
4 Use the array.

On the other hand if you prefer to write code to loop through the recordset and in so doing, get better performance, more power to you.

Anthony

 

by: Jon_RaymondPosted on 2002-02-25 at 23:51:02ID: 6826784

Yes. getrows is great for populating an array.  But, I'd like to see some code that loops through a recordset and compares one row with a previous row - getting better performance.

 

by: CJ_SPosted on 2002-02-26 at 00:23:21ID: 6826826

Jon_Raymond,
 I agree with you that in some cases it would be a great alternative, though it is not recommended. And I have to admit at some times I am doing the exact same thing. Except that that is because I need to pass data in a specified format to a component. In this case it might also work pretty well.

I wouldn't grab the array right away but would first like to know what the exact scenario is. Why do you need to compare with the next recordset? This can probably also be done with a well written SQL statement or other mechanism.

Madhu_28,
can you explain exactly what kind of data you have and why the need exists to compare the recordsets?

ZRegards,
CJ

 

by: rupertsPosted on 2002-02-26 at 02:03:19ID: 6826995

Still if you ONLY need to compare the current row with the next row (I had to do this for a report - and put a break inbetween each department and give totals), then just do the following. (This way you can still use your existing forward only cursor.

do until rs.eof
load the current record department in a variable
Print current Record

rs.movenext
Compare departments, produce sub-totals if the next record is in a different department

loop

 

by: GaryC123Posted on 2003-06-28 at 01:25:38ID: 8818133

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept Answer by Ruperts
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer

 

by: YensidModPosted on 2003-07-06 at 17:54:35ID: 8865943

Per recommendation.

YensidMod
EE Moderator

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...