To read the article online, visit http://www.4GuysFromRolla.com/webtech/071799-1.2.shtml

Using Custom Recordsets, Part 2

By Ryan S.


  • Read Using Custom Recordsets, Part 1
  • In Part 1 we looked at how to create our very own custom recordset. In this part, we are going to look at how we can use this custom recordset in our ASP application!

    Let's say that you want to determine the current user's IP. Well, this ain't too hard:

    'Lock the Application scope
    Application.Lock

    'Get the row based on the Session("ID") for this user
    CustomRS.Find("ID = '" & Session("ID") & "'")

    Response.Write "Your IP is " & CustomRS("IP")

    'Unlock the Application Scope
    Application.UnLock

    Now, what if you want to know the total number of visitors on your website right now? That's easy too!

    'Lock the Application scope
    Application.Lock

    Response.Write "There are " & CustomRS.RecordCount & " visitors on-line right now!"
    'Unlock the Application Scope
    Application.UnLock

    (Note: if all you want to do is see the number of simultaneous visitors on your site, there is a less memory-intensive way to do this. See Joao's aritlce How Many People Are on your Site Right Now?)

    Now, here's the neatest part. You can see a listing of all the folks who are on your site in real time! Just iterate through the recordset:

    'Lock the Application scope...
    Application.Lock
    
    'Move to the first record in our custom recordset
    CustomRS.MoveFirst
    
    'Loop through the recordset...
    Do While Not CustomRS.EOF
    	Response.Write "User: " & CustomRS("ID") & "<BR>"
    	Response.Write "IP: " & CustomRS("IP") & "<BR>"
    	Response.Write "Came on-line at: " & CustomRS("LogOn")
    	Response.Write "<P><HR><P>"
    	
    	CustomRS.MoveNext
    Loop
    
    'Unlock the application...
    Application.UnLock
    

    It's that easy. Pretty freakin' cool, in my opinion.

    Mad props to Professional ADO RDS Programming with ASP, who introduced me to custom recordsets. Mad props to Scott for giving it to me ;-)

    Anyway, hope you had fun with the scriptlet, and as always, God bless from Ryan S

  • Read Using Custom Recordsets, Part 1

  • Attachments:

  • Global.asa for this article


  • Article Information
    Article Title: Using Custom Recordsets, Part 2
    Article Author: Ryan S.
    Published Date: Saturday, July 17, 1999
    Article URL: http://www.4GuysFromRolla.com/webtech/071799-1.2.shtml


    Copyright 2017 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers