Return recordset from function in classic ASP

前端 未结 2 1176
独厮守ぢ
独厮守ぢ 2020-12-11 05:27

I\'m at a loss on how I can return a readable recordset from a function in classic ASP.

This is what I came up with, but it\'s not working:

Response.         


        
相关标签:
2条回答
  • 2020-12-11 05:56

    Here's a function that returns a disconnected recordset

    Function RunSQLReturnRS(sqlstmt, params())
        On Error Resume next
    
        ''//Create the ADO objects
        Dim rs , cmd
        Set rs = server.createobject("ADODB.Recordset")
        Set cmd = server.createobject("ADODB.Command")
    
        ''//Init the ADO objects  & the stored proc parameters
        cmd.ActiveConnection = GetConnectionString()
        cmd.CommandText = sqlstmt
        cmd.CommandType = adCmdText
        cmd.CommandTimeout = 900 
    
        ''// propietary function that put params in the cmd
        collectParams cmd, params
    
        ''//Execute the query for readonly
        rs.CursorLocation = adUseClient
        rs.Open cmd, , adOpenForwardOnly, adLockReadOnly
        If err.number > 0 then
            BuildErrorMessage()
            exit function
        end if
    
        ''// Disconnect the recordset
        Set cmd.ActiveConnection = Nothing
        Set cmd = Nothing
        Set rs.ActiveConnection = Nothing
    
        ''// Return the resultant recordset
        Set RunSQLReturnRS = rs
    
    End Function
    
    0 讨论(0)
  • 2020-12-11 06:04

    Well, you are closing the recordset and connection immediately after setting the function's return variable, so that explains the error messages.

    I am not a VB developer, but I think what you need to look at is Disconnected Recordsets. Take a look at this article, it's doing pretty much exactly what you want.

    0 讨论(0)
提交回复
热议问题