Figure 2   database.cls


 Option Explicit
 Const g_clsName = "Database"
 Dim modDSN As String
 Property Let dsn(dsn As String)
     
     modDSN = dsn
         
 End Property
 
 Function RunWithRS(ByVal strSP As String, strDSN As String) As Variant
     On Error GoTo errorHandler
     
     If strDSN = "" Then
         If modDSN = "" Then
             RunWithRS = -99
         Else
             strDSN = modDSN
         End If
     End If
     ' Set up Command and Connection objects
     Dim rs As ADODB.Recordset, cmd As ADODB.Command
     Set rs = CreateObject("ADODB.Recordset")
     Set cmd = CreateObject("ADODB.Command")
        
     'Run the procedure
     cmd.ActiveConnection = strDSN
     cmd.CommandText = strSP
     cmd.CommandType = adCmdText
     
     rs.CursorLocation = adUseClient
     rs.Open cmd, , adOpenForwardOnly, adLockReadOnly
     Set cmd.ActiveConnection = Nothing
     Set cmd = Nothing
     Set rs.ActiveConnection = Nothing
 
     Set RunWithRS = rs
     Exit Function
     
 errorHandler:
     
 End Function
 
 Function RunWithRS_RW(ByVal strSP As String, Optional strDSN As String) As Variant
     On Error GoTo errorHandler
     
    If strDSN = "" Then
         If modDSN = "" Then
             RunWithRS_RW = -99
         Else
             strDSN = modDSN
         End If
     End If
   
     ' Set up Command and Connection objects
     Dim rs As ADODB.Recordset, cmd As ADODB.Command
     Set rs = CreateObject("ADODB.Recordset")
     Set cmd = CreateObject("ADODB.Command")
        
     'Run the procedure
     cmd.ActiveConnection = strDSN
     cmd.CommandText = strSP
     cmd.CommandType = adCmdText
     
     rs.CursorLocation = adUseClient
     rs.Open cmd, , adOpenDynamic, adLockBatchOptimistic
     Set cmd = Nothing
     
     Set RunWithRS_RW = rs
     Exit Function
     
 errorHandler:
     
 End Function
 
 Function ConvertToString(v As Variant) As String
     If IsNull(v) Then
         ConvertToString = ""
     Else
         ConvertToString = CStr(v)
     End If
 End Function

Figure 4   Properties for Controls on Form

Control
Name
Caption / Text
Textbox
txtDSN
dsn=pubs;uid=sa;pwd=;
Textbox
txtSelect
select * from authors
Textbox
txtOutput

Label
Label1
DSN
Label
Label2
Select
Label
Label3
Output
Command Button
cmdGo
Go


Figure 6   Databasetester.asp Snippets


 Sub thisPage_onenter()
     if thisPage.firstEntered then
         txtDSN.value = "dsn=pubs;uid=sa;pwd=;"
         txtSelect.value = "select * from authors"
     end if
 End Sub
 
 Sub cmdGo_onclick()
 Dim rs , txtOut 
 Dim db 
     
     If txtDSN.value > "" Then
         If txtSelect.value > "" Then
             Set db = server.CreateObject("db.Database")
             Set rs = db.RunWithRS(txtSelect.value, txtDSN.value)
             
             Do While Not rs.EOF
                 txtOut = txtOut & vbCrLf & rs("au_lname")
                 rs.MoveNext
             Loop
             txtOutput.value = txtOut
         End If
     End If
     Set rs = Nothing
     Set db = Nothing
 End Sub