asp(dreamwaver 8.0+xp sp2)+sql server 2000 关键代码
一夜通宵
终于调通了样本代码
如题,
编译环境为:winXP SP2操作系统,dreamwaver 8.0制作工具,ASP页面性质,VBscript脚本,SQL Server 2000数据库。
注意问题:
1.同目录提交跳转页面,超链接可以跳转同目录何不同目录。
2.form标识处配置最近处提交按钮(submit)的行为
3.提交按钮的执行脚本在其将跳转页面下添加,在head和body中间,用<%%〉标识
4.几个重要关键字:response, request, set, ADO
下面是提交页面的脚本:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!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>无标题文档</title>
</head>
<%
name=request.form("adminname") '获取提交按钮Post过来的参数,分别为管理员姓名和密码及校验密码
pwd=request.form("adminpassword")
repwd=request.form("repassword")
Response.Buffer=true
Dim count '定义查询后存在RecordSet对象中数据条数
if name="" or pwd="" or repwd="" then
Response.write "不能有未填项!请重新登录!"
Response.write "<a href=javascript:history.go(-1)>返回</a>"
else
if pwd <> repwd Then
Response.write "验证密码错误!请重新登录!"
Response.write "<a href=javascript:history.go(-1)>返回</a>"
Else
strConnect = "driver=SQL Server;DATABASE=examsysDB;UID=sa;PWD=;SERVER=caiyuancui"
'数据库连接字符串
strsql="select * from administratorTable where adminname='"+name+"' and adminpassword='"+pwd+"'" '查询的sql语句
Set Cnn = Server.CreateObject("ADODB.Connection")
Dim rsTest
'定义临时数据集
Cnn.open strConnect
Set rsTest = Cnn.Execute(strsql)
count = 0
Do While Not rsTest.EOF
count=count+1
rsTest.movenext
Loop
if count=0 then
response.write "密码错误!"
Response.write "<a href=javascript:history.go(-1)>返回</a>"
else
response.write "登录成功!" 'Cstr(count)
'response.redirect "main_management.asp"
'登录成功时的地址再定位
end if
Cnn.close
set rsTest = nothing
End If
end if
%>
<body>
</body>
</html>