6-18.asp

来自「ASP+SQL Server动态网站开发从基础到实践教程」· ASP 代码 · 共 48 行

ASP
48
字号
<!--#include file="adovbs.inc" -->
<html>

<head>

<title>Command对象的Execute方法</title>
</head>

<body>

<%

Dim ConnStr,myConn,mySQL,myRec
ConnStr="Provider=SQLOLEDB;data source=(local);initial catalog=northwind;user id=sa;password=;"  '参照表6-2的连接字符串
Set myConn=Server.CreateObject ("ADODB.Connection")
Myconn.ConnectionString=ConnStr
myConn.open  '直接打开数据库连接

set myComm = Server.CreateObject("ADODB.COMMAND")

myComm.ActiveConnection = myConn
myComm.CommandText = "customers"
myComm.CommandType =adCmdTable
set myRec=myComm.Execute()


response.write "<table border=1>"
'首先输出字段标题,用表格来表示
response.write "<tr><td>客户编号</td><td>公司名称</td><td>联系人</td></tr>" 

do while not myRec.eof    '表示当前记录不是最后
	'输出一条记录
	response.write "<tr><td>" & myRec("customerid") & "</td><td>" & myRec("companyname") & "</td><td>" & myRec("contactname") & "</td></tr>"
	'接着移动到下一条记录
	myRec.movenext  '注意一定要使用这个语句,否则会死循环
loop
response.write "</table>"

myRec.close
myConn.close
set myRs=nothing
set myConn=nothing
%>

</body>

</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?