Command对象

发布时间:2007-03-22 22:56:00 阅读:1247次

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>

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询
下一篇:FSO

转载请注明:Command对象 出自老鄢博客 | 欢迎分享