zoukankan      html  css  js  c++  java
  • 在asp中怎么调用带输出参数的存储过程

    这是我写的存储过程 CREATE proc hz @count2 bigint output, @minsl varchar, @maxsl varchar as create table #tmp(qqno bigint,[check] tinyint,sumsl varchar) create table #tmp1(qqno bigint,friendqqno bigint,addtime datetime,[check] tinyint,sumsl varchar) insert into #tmp select qqno,[check],count(*) as count1 from friendtable group by qqno,[check] order by qqno insert into #tmp1 select #tmp.qqno,friendqqno,addtime,#tmp.[check],sumsl from #tmp left join friendtable on #tmp.qqno=friendtable.qqno where sumsl>=@minsl and sumsl<=@maxsl select @count2=count(*) from #tmp1 GO 在asp中 set o_command=server.createobject("ADODB.Command") set o_command.ActiveConnection=conn1 o_command.CommandText="hz" o_command.CommandType=4 set o_prm=o_command.parameters o_prm.Append o_command.CreateParameter("@count2",adinteger,adParamOutput) o_prm.Append o_command.CreateParameter("@minsl",advarchar,adParamInput,friends) o_prm.Append o_command.CreateParameter("@maxsl",advarchar,adParamInput,friends1) o_command.execute() count2=cmd("@count2") 为什么会出现这样的错误呢? Microsoft VBScript 编译器错误 错误 '800a03f6' 缺少 'End' /iisHelp/common/500-100.asp,行242 Microsoft OLE DB Provider for ODBC Drivers 错误 '80040e14' [Microsoft][ODBC SQL Server Driver][SQL Server]过程 'hz' 需要参数 '@minsl',但未提供该参数。 /friendtable1.asp,行65

    应该有declare吧

    o_prm.Append o_command.CreateParameter("@count2",adinteger,adParamOutput,4) o_prm.Append o_command.CreateParameter("@minsl",advarchar,adParamInput,50) o_prm.Append o_command.CreateParameter("@maxsl",advarchar,adParamInput,50)

    可能adinteger,adParamOutput没赋值吧,在VB里adinteger,adParamOutput等一些常量是有值的,但在ASP中,需要自己为它符值 adCmdSPStoredProc = 4 adParamReturnValue = 4 adParaminput = 1 adParamOutput = 2 adInteger = 3 adVarChar = 200 好了,去试试吧,应该能行的

    count2=赋值 minsl=赋值 maxsl=赋值 set rs=conn.execute("hz '"& count2 &"','"& minsl &"','"& maxsl &"'")

    rs("count2")可以输出

    你在页首加试一下 adovbs.inc这个文件在C:\Program Files\Common Files\System\ado下可以找到如没找到将adInteger这些常量换成原值试一下!

    CreateParameter([Name] , [type] , [Direction] , [Size] , [Value] ) 创建Command对象要使用的新参数。Name是新参数的名称。Type是该参数的数据类型。你可以使用下表所示的任何数据类型: adBigInt 20 8字节有符号整数 adBinary 128 二进制值 adBoolean 11 布尔值 adBSTR 8 Null-中断字符串(Unicode) adChar 129 字符串值 adCurrency 6 货币值 adDate 7 日期值 adDBDate 133 日期值(yyyymmdd) adDBTime 134 时间值(hhmmss) adDBTimeStamp 135 日期时间值(yyyymmddhhmmss) adDecimal 14 具有固定的精度和范围的扩展数字型。 adDouble 5 双精度浮点数值 adEmpty 0 空值 adError 10 32位错误码 adGUID 72 全球唯一的标志码 adIDispatch 9 指向一个OLE对象Idispatch的指针 adInteger 3 4字节有符号整数 adIUnknown 13 指向一个OLE对象Iunkown的指针 adLongVarBinary 205 长二进制值 adLongVarChar 201 长字符串值 adLongVarWChar 203 长NULL-中断字符串值 adNumeric 131 具有固定的精度和范围的扩展数字型。 adSingle 4 单精度浮点值 adSmallInt 2 2字节有符号整数 adTinyInt 16 1字节有符号整数 adUnsignedBigInt 21 8字节无符号整数 adUnsignedInt 19 4字节无符号整数 adUnsignedSmallInt 18 2字节无符号整数 adUnsignedTinyInt 17 1字节无符号整数 adUserDefined 132 未定义变量 adVarBinary 204 二进制值 adVarchar 200 字符串值 adVariant 12 OLE自动变量 adVarWchar 202 NULL-中断Unicode字符串 adWchar 130 NULL-中断Unicode字符串 Direction确定参数是输入参数,输出参数或存储过程的返回值,下表描述了所有你可以使用的Direction值: 常数 值 描述 adParamInput 1 输入参数(缺省值) adParamOutput 2 输出参数 adParamInputOutput 3 输入/输出参数 adParamReturnValue 4 返回值 Size是参数的最大长度,以字节或字符为单位。Value是参数的值。

    这样的方法比较好用 参考一下吧 给存储过程传递参数 : 如果存储过程中不用参数,而是单一的sql语句,还显示不出调用存储过程的优势! 比如说一bbs的查询,可以按作者和主题查询!则可以建立存储过程如下: 参数keyword为关键字,choose是选择查询的方法。 CREATE PROCEDURE [dbo].[dt_bbs] @keyword varchar(20)=null, @choose int=null as if choose=1 select * from bbs where name like @keyword else select * from bbs where subject like @keyword return go 这样我们调用存储过程时只需将参数传递过去就行了,而省去在asp中来写一段程序 用第一种方法: set rs=server.createobject("adodb.recordset") sql="exec dt_bbs '"&keyword&"',"&choose&"" rs.open sql,conn,1,1

  • 相关阅读:
    PKU 1860 Currency Exchange 最短路 bellman
    PKU 3259 Wormholes 最短路 bellman
    bzoj3514
    bzoj2594
    bzoj3901
    bzoj2843&&1180
    bzoj2631
    bzoj2049
    bzoj2002
    bzoj1146
  • 原文地址:https://www.cnblogs.com/trendline/p/356899.html
Copyright © 2011-2022 走看看