开发者

Stored Procedures classic asp

Using the below functions how could I use a stored procedure with parameters.

I have to call a stored procedure using parameters for work experience but i can't seem to work how this would work, usually i would have a command.execute in a recordset parameter then loop through the recordset to get my output.

The below functions are a selected few of which I narrowed down to use. I have called a stored procedure using the recordset function.

recordset

    function Recordset(sNewCommandText, iNewCommandType, iNewCommandTimeout, lng_RecordsetNumber)
            obj_Command.CommandText = sNewCommandText
            if IsNumeric(iNewCommandType) then
                obj_Command.CommandType = iNewCommandType
            else
                obj_Command.CommandType = 1
            end if
            if IsNumeric(iNewCommandTimeout) then
                obj_Command.CommandTimeout = iNewCommandTimeout
            else
                obj_Command.CommandTimeout = 3
            end if
            if RecordsetIsOpen(lng_RecordsetNumber) = 1 then
                CloseRecordset lng_RecordsetNumber
            end if
            select case lng_RecordsetNumber
                case 0
                case 1
 开发者_如何学编程                   obj_Recordset1.Open obj_Command
                case 2
                    obj_Recordset2.Open obj_Command
                case 3
                    obj_Recordset3.Open obj_Command
                case else
                    obj_ExtraRecSets.Item(lng_RecordsetNumber).Open obj_Command
            end select
        end function

Execute

    function Execute(sNewCommandText, iNewCommandType, iNewCommandTimeout)
        Execute= 0
        obj_Command.CommandText = sNewCommandText
        if IsNumeric(iNewCommandType) then
            obj_Command.CommandType = iNewCommandType
        else
            obj_Command.CommandType = 1
        end if
        if IsNumeric(iNewCommandTimeout) then
            obj_Command.CommandTimeout = iNewCommandTimeout
        else
            obj_Command.CommandTimeout = 3
        end if
        obj_Command.Execute
        Execute= 1
    end function

Get field

function GetField(FieldNumber, iFieldAttribute, lng_RecordsetNumber)
        dim lng_tmpcnt
        if RecordsetIsOpen(lng_RecordsetNumber) = 1 and IsNumeric(iFieldAttribute) and BOF(lng_RecordsetNumber) = 0 and EOF(lng_RecordsetNumber) = 0 then
            select case iFieldAttribute
                case 0
                    select case lng_RecordsetNumber
                        case 1
                            GetField = obj_Recordset1.Fields(FieldNumber).Type
                        case 2
                            GetField = obj_Recordset2.Fields(FieldNumber).Type
                        case 3
                            GetField = obj_Recordset3.Fields(FieldNumber).Type
                        case else
                            GetField = obj_ExtraRecSets.Item(lng_RecordsetNumber).Fields(FieldNumber).Type
                    end select
                case 1
                    select case lng_RecordsetNumber
                        case 1
                            GetField = obj_Recordset1.Fields(FieldNumber).Name
                        case 2
                            GetField = obj_Recordset2.Fields(FieldNumber).Name
                        case 3
                            GetField = obj_Recordset3.Fields(FieldNumber).Name
                        case else
                            GetField = obj_ExtraRecSets.Item(lng_RecordsetNumber).Fields(FieldNumber).Name
                    end select 
                case 2
                    select case lng_RecordsetNumber
                        case 1
                            GetField = obj_Recordset1.Fields(FieldNumber).Value
                        case 2
                            GetField = obj_Recordset2.Fields(FieldNumber).Value
                        case 3
                            GetField = obj_Recordset3.Fields(FieldNumber).Value
                        case else
                            GetField = obj_ExtraRecSets.Item(lng_RecordsetNumber).Fields(FieldNumber).Value
                    end select
                case 3
                    select case lng_RecordsetNumber
                        case 1
                            GetField = obj_Recordset1.Fields(FieldNumber).ActualSize
                        case 2
                            GetField = obj_Recordset2.Fields(FieldNumber).ActualSize
                        case 3
                            GetField = obj_Recordset3.Fields(FieldNumber).ActualSize
                        case else
                            GetField = obj_ExtraRecSets.Item(lng_RecordsetNumber).Fields(FieldNumber).ActualSize
                    end select
                case else
                    select case lng_RecordsetNumber
                        case 1
                            for lng_tmpcnt=0 to obj_Recordset1.Fields(FieldNumber).Properties.count-1
                                if lng_tmpcnt <> 15 and lng_tmpcnt <> 17 then
                                    GetField = GetField & lng_tmpcnt & " (" & obj_Recordset1.Fields(FieldNumber).Properties(lng_tmpcnt).name & "(" & obj_Recordset1.Fields(FieldNumber).Properties(lng_tmpcnt).type & ")= " & obj_Recordset1.Fields(FieldNumber).Properties(lng_tmpcnt).value & ")<br>" & vbcrlf
                                end if
                            next 
                        case 2
                            for lng_tmpcnt=0 to obj_Recordset2.Fields(FieldNumber).Properties.count-1
                                if lng_tmpcnt <> 15 and lng_tmpcnt <> 17 then
                                    GetField = GetField & lng_tmpcnt & " (" & obj_Recordset2.Fields(FieldNumber).Properties(lng_tmpcnt).name & "(" & obj_Recordset2.Fields(FieldNumber).Properties(lng_tmpcnt).type & ")= " & obj_Recordset1.Fields(FieldNumber).Properties(lng_tmpcnt).value & ")<br>" & vbcrlf
                                end if
                            next 
                        case 3
                            for lng_tmpcnt=0 to obj_Recordset3.Fields(FieldNumber).Properties.count-1
                                if lng_tmpcnt <> 15 and lng_tmpcnt <> 17 then
                                    GetField = GetField & lng_tmpcnt & " (" & obj_Recordset3.Fields(FieldNumber).Properties(lng_tmpcnt).name & "(" & obj_Recordset3.Fields(FieldNumber).Properties(lng_tmpcnt).type & ")= " & obj_Recordset3.Fields(FieldNumber).Properties(lng_tmpcnt).value & ")<br>" & vbcrlf
                                end if
                            next 
                        case else
                    end select
            end select
        end if
    end function


This function takes the name of the SP and an array of parameters and returns a disconnected recordset

Function RunSPReturnRS(strSP, 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 = strSP
    cmd.CommandType = adCmdStoredProc
    cmd.CommandTimeout = 900 ' 15 minutos

    collectParams cmd, params

    dim i 
    for i = 0 to ubound( Params )
      ''//Use: .CreateParameter("@inVar1", 200, 1, 255, VALUE1) to create the parameters
      cmd.Parameters.Append Params(i)
    next


    ''//Execute the query for readonly
    rs.CursorLocation = adUseClient
    rs.Open cmd, , adOpenForwardOnly, adLockReadOnly

    If err.number > 0 then
        exit function
    end if

    ''//Disconnect the recordset
    Set cmd.ActiveConnection = Nothing
    Set cmd = Nothing
    Set rs.ActiveConnection = Nothing

    ''//Return the resultant recordset
    Set RunSPReturnRS = rs

End Function

Or check this question for more info creating parameters Execute Stored Procedure from Classic ASP

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜