Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 存储过程经典asp_Sql_Stored Procedures_Parameters_Vbscript_Asp Classic - Fatal编程技术网

Sql 存储过程经典asp

Sql 存储过程经典asp,sql,stored-procedures,parameters,vbscript,asp-classic,Sql,Stored Procedures,Parameters,Vbscript,Asp Classic,使用以下函数如何使用带参数的存储过程 我必须使用参数调用一个存储过程以获得工作经验,但我似乎无法确定这是如何工作的,通常我会使用一个命令。在记录集参数中执行,然后在记录集中循环以获得输出 下面的函数是我选择使用的几个函数。我使用recordset函数调用了一个存储过程 记录集 function Recordset(sNewCommandText, iNewCommandType, iNewCommandTimeout, lng_RecordsetNumber) o

使用以下函数如何使用带参数的存储过程

我必须使用参数调用一个存储过程以获得工作经验,但我似乎无法确定这是如何工作的,通常我会使用一个命令。在记录集参数中执行,然后在记录集中循环以获得输出

下面的函数是我选择使用的几个函数。我使用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
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
执行

    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
上场

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
函数GetField(FieldNumber,iFieldAttribute,lng\U RecordsetNumber)
dim lng\U tmpcnt
如果RecordsetIsOpen(lng_RecordsetNumber)=1,IsNumeric(iFieldAttribute),BOF(lng_RecordsetNumber)=0,EOF(lng_RecordsetNumber)=0,则
选择案例属性
案例0
选择案例lng\U记录集编号
案例1
GetField=obj_Recordset1.Fields(FieldNumber).Type
案例2
GetField=obj_Recordset2.Fields(FieldNumber).Type
案例3
GetField=obj_Recordset3.字段(FieldNumber).类型
其他情况
GetField=obj_extracrecsets.Item(lng_RecordsetNumber).Fields(FieldNumber).类型
结束选择
案例1
选择案例lng\U记录集编号
案例1
GetField=obj_Recordset1.Fields(FieldNumber).Name
案例2
GetField=obj_Recordset2.Fields(FieldNumber).Name
案例3
GetField=obj_Recordset3.Fields(FieldNumber).Name
其他情况
GetField=obj_extracrecsets.Item(lng_RecordsetNumber).Fields(FieldNumber).Name
结束选择
案例2
选择案例lng\U记录集编号
案例1
GetField=obj_Recordset1.Fields(FieldNumber).Value
案例2
GetField=obj_Recordset2.Fields(FieldNumber).Value
案例3
GetField=obj_Recordset3.Fields(FieldNumber).Value
其他情况
GetField=obj_extracrecsets.Item(lng_RecordsetNumber).Fields(FieldNumber).Value
结束选择
案例3
选择案例lng\U记录集编号
案例1
GetField=obj_Recordset1.Fields(FieldNumber).ActualSize
案例2
GetField=obj_Recordset2.Fields(FieldNumber).ActualSize
案例3
GetField=obj_Recordset3.Fields(FieldNumber).ActualSize
其他情况
GetField=obj_外部记录集。项(lng_记录集编号)。字段(字段编号)。实际化
结束选择
其他情况
选择案例lng\U记录集编号
案例1
对于lng_tmpcnt=0到obj_Recordset1.Fields(FieldNumber).Properties.count-1
如果lng_tmpcnt 15和lng_tmpcnt 17,则
GetField=GetField&lng_-tmpcnt&“(”&obj_-Recordset1.Fields(FieldNumber).Properties(lng_-tmpcnt).name&“(”&obj_-Recordset1.Fields(FieldNumber).Properties(lng_-tmpcnt).value&“
”&vbcrlf 如果结束 下一个 案例2 对于lng_tmpcnt=0到obj_记录集2.字段(FieldNumber).Properties.count-1 如果lng_tmpcnt 15和lng_tmpcnt 17,则 GetField=GetField&lng_-tmpcnt&“(”&obj_-Recordset2.Fields(FieldNumber).Properties(lng_-tmpcnt).name&“(”&obj_-Recordset2.Fields(FieldNumber).Properties(lng_-tmpcnt).Properties(”&obj_-Recordset1.Fields(FieldNumber).Properties(lng_-tmpcnt).value&“
”&vbcrlf 如果结束 下一个 案例3 对于lng_tmpcnt=0到obj_记录集3.字段(FieldNumber).Properties.count-1 如果lng_tmpcnt 15和lng_tmpcnt 17,则 GetField=GetField&lng_-tmpcnt&“(”&obj_-Recordset3.Fields(FieldNumber).Properties(lng_-tmpcnt).name&“(”&obj_-Recordset3.Fields(FieldNumber).Properties(lng_-tmpcnt).value&“
”&vbcrlf 如果结束 下一个 其他情况 结束选择 结束选择 如果结束 端函数
此函数获取SP的名称和参数数组,并返回断开连接的记录集

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
或者检查此问题以了解创建参数的更多信息