zoukankan      html  css  js  c++  java
  • asp调用存储过程

    <table width="360" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#9EC4EB">
    <form name="form1" method="post" action="">
      <tr background="images/bg.jpg">
        <td height="27" style="text-indent:40px"><span class="style1">调用SQL Server存储过程</span></td>
      </tr>
      <tr bgcolor="#FFFFFF">
        <td height="35" align="center"><input name="bt_call" type="button" id="bt_call" value="使用call语句调用" onClick="javascript:window.location.href='index.asp?action=cal';"></td>
        </tr>
      </form>
    </table>
    <br>
    <%
    action=Request.QueryString("action")
      If action="cal" Then
        Set rs=Server.CreateObject("ADODB.Recordset")
        sqlstr="{call User_proc}"
     rs.open sqlstr,conn,1,1 
    %>
    <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#9EC4EB">
      <tr align="center">
        <td height="22">用户名</td>
        <td height="22">用户等级</td>
        <td height="22">联系方式</td>
      </tr>
      <%While Not rs.eof%>
      <tr align="center" bgcolor="#FFFFFF">
        <td height="22"><%=rs("UserName")%></td>
        <td height="22"><%=rs("ULevel")%></td>
        <td height="22"><%=rs("Utel")%></td>
      </tr>
      <%rs.movenext
        Wend
     rs.close
     Set rs=Nothing
      %>
    </table>
    <%End If%>

    <table width="360" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#9EC4EB">
    <form name="form1" method="post" action="">
      <tr background="images/bg.jpg">
        <td height="27" style="text-indent:40px"><span class="style1">调用SQL Server存储过程</span></td>
      </tr>
      <tr bgcolor="#FFFFFF">
        <td height="35" align="center"><input name="bt_comd" type="button" id="bt_comd" value="通过Command对象调用" onClick="javascript:window.location.href='index.asp?action=comd';"></td>
        </tr>
      </form>
    </table>
    <br>
    <%
    action=Request.QueryString("action") 
      If action="comd" then
        Const adCmdStoredProc = &H0004
        Set cmd=Server.CreateObject("ADODB.Command")
     cmd.ActiveConnection=conn
     cmd.CommandText="User_proc"
     cmd.CommandType=adCmdStoredProc
     Set rs=cmd.Execute 
    %>
    <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#9EC4EB">
      <tr align="center">
        <td height="22">用户名</td>
        <td height="22">用户等级</td>
        <td height="22">联系方式</td>
      </tr>
      <%While Not rs.eof%>
      <tr align="center" bgcolor="#FFFFFF">
        <td height="22"><%=rs("UserName")%></td>
        <td height="22"><%=rs("ULevel")%></td>
        <td height="22"><%=rs("Utel")%></td>
      </tr>
      <%rs.movenext
        Wend
     rs.close
     Set rs=Nothing
      %>
    </table>
    <%End If%>

    <%
    If Not Isempty(Request("sure")) Then
      txt_name=Request.Form("txt_name")
      txt_pwd=Request.Form("txt_pwd")
      If txt_name<>"" and txt_pwd<>"" Then
        Const adCmdStoredProc = &H0004
     Const adVarChar=200
        Const adChar = 129
        Const adParamInput=&H0001
        Set cmd=Server.CreateObject("ADODB.Command")
     cmd.ActiveConnection=conn
     cmd.CommandText="user_check"
     cmd.CommandType=adCmdStoredProc
     set param=cmd.CreateParameter("@username",adVarChar,adParamInput,50)
     cmd.Parameters.Append param
     cmd.Parameters("@username")=txt_name
     set param=cmd.CreateParameter("@upwd",adChar,adParamInput,10)
     cmd.Parameters.Append param
     cmd.Parameters("@upwd")=txt_pwd
     Set rs=cmd.Execute()
     If (rs.eof or rs.bof) Then
       Response.write "<script language='javascript'>alert('此用户不存在,请重新输入!');window.location.href='index.asp';</script>"
     Else
       Response.write "<script language='javascript'>alert('用户登录成功!');window.location.href='index.asp';</script>"
     End If
      End If
    End If
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>如何调用带输入参数的存储过程</title>
    </head>
    <body style="font-size:12px">
    <table width="352" height="193" border="0" align="center" cellpadding="2" cellspacing="1" background="images/bg.JPG">
    <form name="form1" method="post" action="">
      <tr valign="bottom">
        <td height="25" colspan="2" style="text-indent:35px">用户登录</td>
      </tr>
      <tr height="21">
        <td width="103" align="right">用户名:</td>
        <td width="238"><input name="txt_name" type="text" id="txt_name"></td>
      </tr>
      <tr height="21">
        <td height="42" align="right">密 码:</td>
        <td><input name="txt_pwd" type="password" id="txt_pwd"></td>
      </tr>
      <tr  height="26">
        <td align="right">&nbsp;</td>
        <td valign="top"><input name="sure" type="submit" id="sure" value="登录">
          <input type="reset" name="Submit2" value="重置"></td>
      </tr>
      </form>
    </table>
    </body>

    <%
    If Not Isempty(Request("sure")) Then
        Const adCmdStoredProc = &H0004
     Const adVarChar=200
        Const adParamOutput = &H0002
        Set cmd=Server.CreateObject("ADODB.Command")
     cmd.ActiveConnection=conn
     cmd.CommandText="score_view"
     cmd.CommandType=adCmdStoredProc
     set param=cmd.CreateParameter("@highscore",adVarChar,adParamOutput,30)
     cmd.Parameters.Append param
     set param=cmd.CreateParameter("@lowscore",adVarChar,adParamOutput,30)
     cmd.Parameters.Append param
     cmd.Execute()
     highscore=cmd.Parameters("@highscore")
     lowscore=cmd.Parameters("@lowscore")
    End If
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>如何获取存储过程中的输出参数值</title>
    </head>
    <body>
    <table width="237" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CBFBFF">
      <tr>
        <td height="25" colspan="2" style="text-indent:30px" background="images/bg.jpg">获取存储过程中的输出参数值</td>
      </tr>
      <tr align="left" bgcolor="#FFFFFF">
        <td width="90" height="28">最高分数:</td>
        <td width="144" height="28"><%=highscore%></td>
      </tr>
      <tr align="left" bgcolor="#FFFFFF">
        <td height="28">最低分数:</td>
        <td height="28"><%=lowscore%></td>
      </tr>
      <tr align="center" bgcolor="#FFFFFF">
      <form name="form1" method="post" action="">
        <td height="28" colspan="2"><input name="sure" type="submit" id="sure" value="确定查询"></td>
        </form>
      </tr>
    </table>
    </body>

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>如何获取存储过程参数信息</title>
    </head>
    <body style="font-size:12px">
    <table width="400" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#DCE1FC">
    <caption style="font-size:14px">存储过程参数信息<br>
    </caption>
      <tr align="center">
        <td height="26">参数名</td>
        <td height="26">数据类型</td>
        <td height="26">指定方向</td>
        <td height="26">长度</td>
      </tr>
      <%Const adCmdStoredProc = &H0004
        Set cmd=Server.CreateObject("ADODB.Command")
     cmd.ActiveConnection=conn
     cmd.CommandText="user_check"
     cmd.CommandType=adCmdStoredProc
     For each param in cmd.Parameters
      %>
      <tr align="center" bgcolor="#FFFFFF">
        <td height="26"><%=param.name%></td>
        <td height="26"><%=param.type%></td>
        <td height="26"><%=param.direction%></td>
        <td height="26"><%=param.size%></td>
      </tr>
      <%
       Next
       conn.close
       Set conn=Nothing
      %>
    </table>

    本文用到没有用到adodb.command命令,只是简单的做了一个用adodb.recordset来执行存储过程。

    存储过程:
    '在SQL中建立dbo.tse存储过程

    CREATE PROCEDURE [dbo].[tse]
    @keyword varchar(20)=null,  '定义查询的关键字
    @choose int=null                    '定义查询的类型(1为查询列title,其他为content)
    as
    if @choose=1
    select * from web where title like @keyword + '%'
    else
    select * from web where content like @keyword + '%'
    return
    GO



    'list.asp页
    <!--#include file="conn.inc" -->
    <%
    dim rs
    dim sql
    dim keyword
    dim choose
    keyword=request(“keyword“) '接收页面传送的值
    choose=request(“choose“)
    set rs=server.createobject("adodb.recordset")
    sql="exec tse '"&keyword&"',"&choose&""     '用exec执行tse存储过程,把keyword,choose给存储过程传递参数
    rs.open sql,conn,1,1
    if rs.eof and rs.bof then
    response.write("没有任何记录!")
    response.end
    end if
    response.write"搜索到的记录如下:<br><br>"
    do until rs.eof  
    response.write""&rs("id")&":"&rs("title")&""   '打印出文章的ID和标题
    response.write"<br><br>"
    rs.movenext
    loop
    '打扫战场
    rs.close
    conn.close
    set rs=nothing           
    set conn = nothing   
    %>

  • 相关阅读:
    倒排索引在MYSQL,PostgreSQL,ElasticSearch中的设计思想
    MySQL Group Replication: What Is It? Replicated Database State Machine & Paxos implementation
    Redis 6.0 docker Cluster
    What is the "Docker Subnet" used for?
    Windows MYSQL 8.0 或者 5.7 查找my.ini 修改端口号
    Kerberos Network Authentication Service Window & Mac
    协合新能源集团有限公司 | 红海 eHR BPMN
    基于 springBoot 实现webSocket方式的扫码登录
    Python中IO编程-StringIO和BytesIO
    Neo4j基本入门
  • 原文地址:https://www.cnblogs.com/fslnet/p/1649049.html
Copyright © 2011-2022 走看看