Asp执行存储过程

存储过程在上篇日志中.

1.common.asp

<body style="font-size:12px;font-family:arial;">
<%
response.charset="gb2312"
Function sql_conn()
 dim Conn,Strconn
 set Conn=server.createobject("adodb.connection")
 Strconn = "driver={SQL Server}; server=YANSIYU; uid=sa; pwd=admin; database=test;"
 Conn.open Strconn
 set sql_conn=Conn
 If Err Then
 err.Clear
 Conn.close:set Conn=nothing
 Response.Write "对不起,数据库连接出错。"
 Response.End
 End If
End Function
Set objComm = Server.CreateObject("adodb.command")
objComm.CommandType = 4
objComm.ActiveConnection = sql_conn
objComm.CommandText = "sp1"
Set objRs = objComm.execute
if not objRs.eof then
do while not objRs.eof
    Response.write objRs(0) &"--"
    Response.write objRs(1) &"--"
    Response.write objRs(2) &"--"
    Response.write objRs(3)
 Response.write "<br/>"
objRs.movenext
loop
else
response.write "数据库为空"
end if
Set objRs = Nothing
Set objComm = Nothing
%>
</body>
 

2.outsp.asp

<%
response.charset="gb2312"
Function sql_conn()
 dim Conn,Strconn
 set Conn=server.createobject("adodb.connection")
 Strconn = "driver={SQL Server}; server=YANSIYU; uid=sa; pwd=admin; database=test;"
 Conn.open Strconn
 set sql_conn=Conn
 If Err Then
 err.Clear
 Conn.close:set Conn=nothing
 Response.Write "对不起,数据库连接出错。"
 Response.End
 End If
End Function
set comm=server.CreateObject("adodb.command")
comm.activeconnection=sql_conn
comm.commandtext="sp4" 
comm.commandtype=4
set p1=comm.createparameter("aa",129,2,5)   '("名称随意",,2表示输出,长度) (name,type,direction,size,value)   
comm.parameters.Append p1
comm.execute
response.write comm("aa")
set comm=nothing
%>

 

3.insp.asp

<body style="font-size:12px;font-family:arial;">
<%
response.charset="gb2312"
Function sql_conn()
 dim Conn,Strconn
 set Conn=server.createobject("adodb.connection")
 Strconn = "driver={SQL Server}; server=YANSIYU; uid=sa; pwd=admin; database=test;"
 Conn.open Strconn
 set sql_conn=Conn
 If Err Then
 err.Clear
 Conn.close:set Conn=nothing
 Response.Write "对不起,数据库连接出错。"
 Response.End
 End If
End Function
Set objComm = Server.CreateObject("adodb.command")
objComm.Parameters.append objComm.CreateParameter("@username",200,1,50)  '(name,type,direction,size,value)
objComm.CommandType = 4
objComm.ActiveConnection = sql_conn
objComm.CommandText = "sp2"
username=request("username")
if username<>"" then
username=request("username")
else
username="test"
end if
objComm.Parameters("@username") = username
Set objRs = objComm.execute
If not objRs.eof Then
    Response.write objRs(0) &"--"
    Response.write objRs(1)
else
    Response.write "sorry~"
End if
Set objRs = Nothing
Set objComm = Nothing
%>
</body>
 

4.inspid.asp

<body style="font-size:12px;font-family:arial;">
<%
response.charset="gb2312"
Function sql_conn()
 dim Conn,Strconn
 set Conn=server.createobject("adodb.connection")
 Strconn = "driver={SQL Server}; server=YANSIYU; uid=sa; pwd=admin; database=test;"
 Conn.open Strconn
 set sql_conn=Conn
 If Err Then
 err.Clear
 Conn.close:set Conn=nothing
 Response.Write "对不起,数据库连接出错。"
 Response.End
 End If
End Function
Set objComm = Server.CreateObject("adodb.command")
objComm.Parameters.append objComm.CreateParameter("@id",200,1,50)
objComm.CommandType = 4
objComm.ActiveConnection = sql_conn
objComm.CommandText = "sp2_2"
id=request("id")
if id<>"" then
id=request("id")
else
id=3
end if
objComm.Parameters("@id") = id
Set objRs = objComm.execute
If not objRs.eof Then
    Response.write objRs(0) &"--"
    Response.write objRs(1) &"--"
 Response.write objRs(2)
else
    Response.write "sorry~"
End if
Set objRs = Nothing
Set objComm = Nothing
%>
</body>
 

5.inoutsp.asp

<form id="form1" name="form1" method="post" action="?action=send">
  <p>
    <input type="text" name="username" />
 </p>
  <p>  
    <input type="password" name="pwd" />
  </p>
  <p>
    <input type="submit" name="Submit" value="提交" />
      <input type="reset" name="reset" value="重置" />
  </p>
</form>

<%
if request("action")="send" then
response.charset="gb2312"
Function sql_conn()
 dim Conn,Strconn
 set Conn=server.createobject("adodb.connection")
 Strconn = "driver={SQL Server}; server=YANSIYU; uid=sa; pwd=admin; database=test;"
 Conn.open Strconn
 set sql_conn=Conn
 If Err Then
 err.Clear
 Conn.close:set Conn=nothing
 Response.Write "对不起,数据库连接出错。"
 Response.End
 End If
End Function
set comm=server.CreateObject("adodb.command")
comm.activeconnection=sql_conn
comm.commandtext="login" 
comm.commandtype=4
set p1=comm.createparameter("@fullname",200,1,50,request("username"))
comm.parameters.Append p1
set p1=comm.createparameter("@inpassword",200,1,50,request("pwd"))
comm.parameters.Append p1
set p1=comm.createparameter("check",129,2,3)
comm.parameters.Append p1
comm.execute
if comm("check")="yes" then
%>
<script>alert('欢迎光临');</script>
<%
else
%>
<script>alert('用户名或密码错误')</script>
<%
end if
set comm=nothing
%>
<%end if%>
 

6.adddata.asp

<%
response.charset="gb2312"
Function sql_conn()
 dim Conn,Strconn
 set Conn=server.createobject("adodb.connection")
 Strconn = "driver={SQL Server}; server=YANSIYU; uid=sa; pwd=admin; database=test;"
 Conn.open Strconn
 set sql_conn=Conn
 If Err Then
 err.Clear
 Conn.close:set Conn=nothing
 Response.Write "对不起,数据库连接出错。"
 Response.End
 End If
End Function
set comm=server.CreateObject("adodb.command")
comm.activeconnection=sql_conn
comm.commandtext="test3" 
comm.commandtype=4
comm.Parameters.append comm.CreateParameter("@username",200,1,50)  '(name,type,direction,size,value)
comm.Parameters.append comm.CreateParameter("@age",200,1,50)  '(name,type,direction,size,value)
username=request("username")
if username<>"" then
username=request("username")
else
username="auto"
end if
age=cint(request("age"))
if age<>"" then
age=cint(request("age"))
else
age=100
end if
comm.Parameters("@username") = username
comm.Parameters("@age") = age
comm.execute
response.write "success"
set comm=nothing
%>

    A+
发布日期:2009年04月17日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: