建立链接
- conn.asp
- <%
- dim conn
- set conn = server.createobject("adodb.connection")
- conn.open "driver={sql server};database=guest;server=(local);uid=sa;pwd=password"
- %>
- <%
- rs.close
- set rs = nothing
- conn.close
- set conn = nothing
- %>
ASP链接sql server--数据库查询
- <!--#include file="conn.asp"-->
- <%
- response.charset = "GBK"
- dim rs,sql
- set rs = server.createobject("adodb.recordset")
- sql = "select * from g_reg"
- rs.open sql,conn,1,1
- %>
- <html>
- <head>
- <title>注册留言板</title>
- </head>
- <body>
- <table border="1" align="center" width="800">
- <caption>用户管理</caption>
- <tr><th>id</th><th>用户名</th><th>性别</th><th>年龄</th><th>电子邮件</th><th>注册时间</th><th>操作</th></tr>
- <%
- do while not rs.eof
- %>
- <tr><td><%=rs("g_id")%></td><td><%=rs("g_username")%></td><td><%=rs("g_sex")%></td><td><%=rs("g_age")%></td><td><%=rs("g_email")%></td><td><%=rs("g_date")%></td><td><a href="modify.asp?id=<%=rs("g_id")%>">修改</a> | <a href="del.asp?id=<%=rs("g_id")%>">删除</a></td></tr>
- <%
- rs.movenext
- loop
- %>
- </table>
- </body>
- </html>
- <%
- rs.close
- set rs = nothing
- conn.close
- set conn = nothing
- %>
asp链接sql server数据库,登录的验证,和登录信息的保存
登录页面 login.asp
- <html>
- <head>
- <title>注册留言板</title>
- </head>
- <body>
- <form method="post" action="login_do.asp">
- <dl>
- <dt>会员注册</dt>
- <dd>用户名:<input type="text" name="username" /></dd>
- <dd>密 码:<input type="password" name="password" /></dd>
- <dd><input type="submit" value="登录" /></dd>
- </dl>
- </form>
- </body>
- </html>
登录处理页面login_do.asp
- <!--#include file="conn.asp"-->
- <%
- response.charset = "GBK"
- dim username,password,rs,sql,level
- username = request.form("username")
- password = request.form("password")
- '实现数据库验证
- set rs = server.createobject("adodb.recordset")
- sql = "select g_username,g_password,g_level from g_reg where g_username='"&username&"' and g_password='"&password&"'"
- rs.open sql,conn,1,1
- '判断是否有数据
- if not rs.eof then
- if rs("g_level") = true then
- session("admin") = username
- end if
- response.cookies("login") = username
- response.redirect "write.asp"
- else
- response.write "<script>alert('用户名或密码不正确');history.back();</script>"
- end if
- rs.close
- set rs = nothing
- conn.close
- set conn = nothing
- %>
使用asp链接sql server数据库,得到url中的id进行删除操作
del.asp
- <!--#include file="conn.asp"-->
- <%
- response.charset = "GBK"
- dim sql
- sql = "DELETE FROM g_reg WHERE g_id="&request.querystring("id")
- conn.execute(sql)
- response.redirect "index.asp"
- %>
分页代码
- <!--#include file="conn.asp"-->
- <%
- dim rs
- set rs = server.createobject("adodb.recordset")
- rs.open "零件报价表",conn,1,1
- '首先必须设置每页多少条
- rs.pagesize = 5 '目前设置了每页10条
- '我来接受页码
- '接收到得值为字符串,必须转换成整数比较
- 'cint(接收),可以比较了
- '先判断是否为字符串,如果是的话,就rs.absolutepage = 1
- '如果不是,再判断是否为空,是否为小于1,大于最大的页码
- if isnumeric(request.querystring("page")) then
- if request.querystring("page") = "" or cint(request.querystring("page"))<1 then
- rs.absolutepage = 1
- elseif cint(request.querystring("page"))>rs.pagecount then
- rsrs.absolutepage = rs.pagecount
- else
- rs.absolutepage = request.querystring("page")
- end if
- else
- rs.absolutepage = 1
- end if
- %>
- <html>
- <head>
- <title>数据库分页技术</title>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- </head>
- <body>
- <p align="center">一共有<%=rs.recordcount%>条数据</p>
- <p align="center">
- <%
- for i = 1 to rs.pagecount
- response.write "<a href='11-15.asp?page="&i&"'>" & i & "</a> | "
- next
- %>
- </p>
- <table border="1" width="600" align="center">
- <tr><th>编号</th><th>零件种类</th><th>厂家</th><th>规格</th><th>价格</th><th>报价日期</th></tr>
- <%
- for i=1 to rs.pagesize
- if rs.eof then exit for
- %>
- <tr><td><%=rs("编号")%></td><td><%=rs("零件种类")%></td><td><%=rs("厂家")%></td><td><%=rs("规格")%></td><td><%=rs("价格")%></td><td><%=rs("报价日期")%></td></tr>
- <%
- rs.movenext
- next
- %>
- </table>
- </body>
- </html>
- <!--#include file="close.asp"-->