Command对象

conn.asp

<%
set conn=Server.CreateObject("ADODB.Connection")
DBPath=Server.MapPath("db1.mdb")
conn.Open "provider=microsoft.jet.oledb.4.0;data source="&dbpath
%>

sqlcn.asp

<%
on error resume next
Set conn=Server.CreateObject("ADODB.Connection")
conn.open "Provider=Sqloledb;User Password=admin; Initial Catalog=victor; Data Source=127.0.0.1;"
%>
 

 

command1.asp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>abc</title>
</head>
<!--#include file="conn.asp"-->
<body>
<%
set cmd=server.CreateObject("adodb.command")
cmd.activeconnection=conn
cmd.commandtext="select *from forum"   'sql语句
cmd.commandtype=1
cmd.commandtimeout=30
cmd.prepared=true
set rs=cmd.execute
do while not rs.eof
  response.write rs("topic") & "<br/>"
  rs.movenext
loop
cmd.close
set cmd=nothing
conn.close
set conn=nothing
%>
</body>
</html>

command2.asp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>abc</title>
</head>
<!--#include file="conn.asp"-->
<body>
<%
set cmd=server.CreateObject("adodb.command")
cmd.activeconnection=conn
cmd.commandtext="forum"    '表名
cmd.commandtype=2
cmd.commandtimeout=30
cmd.prepared=true
set rs=cmd.execute
do while not rs.eof
  response.write rs("topic") & "<br/>"
  rs.movenext
loop
cmd.close
set cmd=nothing
conn.close
set conn=nothing
%>
</body>
</html>

command3.asp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>abc</title>
</head>
<!--#include file="sqlcn.asp"-->
<body>
<%
set cmd=server.CreateObject("adodb.command")
cmd.activeconnection=conn
cmd.commandtext="selection"   '瀛樺偍杩囩▼鍚?
'鏃犲弬 create procedure selection as select *from forum  GO   璋冪敤鏃? exec selection
'鏈夊弬 CREATE PROCEDURE sel  @character varchar(10)  as select *from forum where topic=@character GO  璋冪敤鏃? exec sel @character=''
cmd.commandtype=4
cmd.commandtimeout=30
cmd.prepared=true
set rs=cmd.execute
do while not rs.eof
  response.write rs("topic") & "<br/>"
  rs.movenext
loop
cmd.close
set cmd=nothing
conn.close
set conn=nothing
%>
</body>
</html>
 

command4.asp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>abc</title>
</head>
<!--#include file="conn.asp"-->
<body>
<%
set cmd=server.CreateObject("adodb.command")
cmd.activeconnection=conn
cmd.commandtext="selection" '查询名
cmd.commandtype=4
cmd.commandtimeout=30
cmd.prepared=true
set rs=cmd.execute
do while not rs.eof
  response.write rs("topic") & "<br/>"
  rs.movenext
loop
cmd.close
set cmd=nothing
conn.close
set conn=nothing
%>
</body>
</html>
 

command5.asp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>abc</title>
</head>
<!--#include file="sqlcn.asp"-->
<body>
<%
sql="exec selection"  '无参 create procedure selection as select *from forum  GO   调用时: exec selection'
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,2
response.write rs("id") & "<br/>"
%>

<%
sql="exec sel @character='五笔字型'"
set rs=conn.execute(sql)
'do while not rs.eof
response.write rs("topic") & "<br/>"
'rs.movenext
'loop
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
</body>
</html>

    A+
发布日期:2007年03月22日  所属分类:未分类

发表评论

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