When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Wednesday, August 16, 2000

How To Pass a Recordset From a VB Component to an ASP Page, Part 2

By Doug Dean


  • Read Part 1

  • In Part 1 we looked at creating the VB server-side DLL. In this part we'll look at the ASP page that obtains the disconnected recordset from the VB component in Part 1!

    - continued -

    THE ASP FILE - How2Project1.asp
    We'll need to instantiate the VB object within the asp file with the following statement and then assign values to the two parameters used in the method.

    '~~~~~~~~~~~~~~~~~~ Set Object ~~~~~~~~~~~~~~~~~
    Set oClass = Server.CreateObject("How2Project1.ClassName")
    
    '~~~~~~~~~~~~ Set method parameters ~~~~~~~~~~~~~
    strDbConnectionString = "strDSN"
    strSQL = "Select ExampleField1, ExampleField2 From ExampleTable"
    

    Literal constant values could be used directly within the method definition, but this can get messy when more than a few arguments are used. Since we're calling a method that returns a RecordSet object (remember, Set was used for sending the RecordSet object in our VB code), we'll need to use Set for assigning the object variable (oRecordSet) we use here in our asp code to accept the sent RecordSet.

    '~~~~~~~~~~~~~~ Get Detached RecordSet ~~~~~~~~~~
    Set oRecordSet = oClass.MethodName(strDbConnectionString, strSQL)

    Now we have a RecordSet object variable that can be used to obtain the database field values. In this example, we'll loop though the records and use the Response.Write method to send the values back to any visiting browser as HTML text. The two returned ExampleField1 and ExampleField2 fields values from the Example1 database will be displayed like this…

    100 Text Field 2a
    200 Text Field 2b
    300 Text Field 2c
    400 Text Field 2d
    500 Text Field 2e
    600 Text Field 2f 
    

    Here's the asp code that lists the fields…

    '~~~ Get Detached RecordSet send from the component ~~~
    oRecordSet.Open
    
    '~~~~~~ Check if RecordSet is empty or not ~~~~~~
    If oRecordSet.EOF = True And oRecordSet.BOF = True Then
      '-----> RecordSet is empty if programming flow goes here
    
    Else
      oRecordSet.MoveFirst
    
      '========== Loop through RecordSet until "End Of File" ==========
      Do While Not oRecordSet.EOF
    
        '-----> Send field values to HTML page
        Response.Write(oRecordSet.Fields("ExampleField1") & " ")
        Response.Write(oRecordSet.Fields("ExampleField2") & "<BR>")
    
      '-----> Increment to next record 
      oRecordSet.MoveNext
      Loop
      '===================================================
    
    End If 
    
    '~~~~~~~~~~~~~~~ Close RecordSet ~~~~~~~~~~~~~~~~
    oRecordSet.Close
    
    '~~~~~~~~~~~~~ Set Objects to Nothing ~~~~~~~~~~~
    Set oClass = Nothing
    Set oRecordSet = Nothing
    

    Happy Programming!

  • By Doug Dean


    Attachments:

  • Download the project files in ZIP format


  • ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article