asp页面
作 者 : 青苹果电脑工作室
这个例子中的第一站是asp页。这个asp页用ado与northwind 数据库连接。为了保持良好的编码习惯,我
使用了option explicit 并明确地声明了所有变量。这个asp页的第一个草稿使用了内联代码。
< % @ language=vbscript % >
< %
example of inline code
option explicit
declare variables
dim oconn
dim ors
dim connectionstring
dim x
connectionstring = "dsn=northwind;"
set oconn = server.createobject("adodb.connection")
oconn.open connectionstring
set ors = server.createobject("adodb.recordset")
set variables
ors.activeconnection = oconn
ors.source = "select * from products"
ors.open
% >
< html >
< head >
< meta http-equiv="content-type" content="text/html; charset=windows-1252" >
< title >new page 1< /title >
< /head >
< body >
< h1 >products< /h1 >
< table cellspacing="2" cellpadding="5" >
< tr bgcolor="#ff6666" >
< th >product name< /th >
< th >quantity per unitr< /th >
< th >price< /th >
< /tr >
< %
do until ors.eof
if x = 1 then
x = 0
% >
< tr bgcolor="#ffcccc" >
< % else % >
< tr >
< %
x = 1
end if
% >
< td >< %=ors("productname")% >< /td >
< td >< %=ors("quantityperunit")% >< /td >
< td >< %=ors("unitprice")% >< /td >
< /tr >
< %
ors.movenext
loop
% >
< /table >
< /body >
< /html >
< %
destroy objects
set ors = nothing
set oconn = nothing
% >
