| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 666 人关注过本帖
标题:共同学习asp (简单的人员管理)
只看楼主 加入收藏
calcano
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-9-6
收藏
 问题点数:0 回复次数:4 
共同学习asp (简单的人员管理)

db

<%
dim db,strCon
strCon="Dbq="&Server.MapPath("db.mdb")&";Driver={Microsoft Access Driver (*.mdb)}"
Set db=Server.CreateObject("ADODB.Connection")
db.Open strCon
%>


add
<!--#include file="db.asp"-->
<%
On Error Resume Next
If Trim(Request("name"))="" Or Trim(Request("password"))=""Then
Response.Write "对不起,姓名和密码必须输入"
Response.Write "<p><a href='add_form.htm'>返回,重新填写</a>"
Else
Dim name,password,tel,email,home,age,intro
name=Request("name")
password=Request("password")
tel=Request("tel")
home=Request("home")
email=Request("email")
age=Request("age")
intro=Request("intro")

Dim strSql,sqla,sqlb
sqla = "Insert Into user(name,password"
sqlb = "Values('" & name & "','" & password & "'"
If tel<>"" Then
sqla = sqla & ",tel"
sqlb = sqlb & ",'" & tel & "'"
End If
If home<>"" Then
sqla = sqla & ",home"
sqlb = sqlb & ",'" & home & "'"
End If
If email<>"" Then
sqla = sqla & ",email"
sqlb = sqlb & ",'" & email & "'"
End If
If age<>"" Then
sqla = sqla & ",age"
sqlb = sqlb & ",'" & age & "'"
End If
If intro<>"" Then
sqla = sqla & ",intro"
sqlb = sqlb & ",'" & intro & "'"
End If
strSql = sqla & ") " & sqlb & ")"
db.Execute(strSql)

If db.Errors.Count>0 Then
Response.Write "保存过程中发生错误,必须重新填写"
Response.Write "<p><a href='add_form.htm'>返回,重新填写</a>"
Else
Response.Write "<h2 align='center'>您的信息已经安全加入,请牢记密码</h2>"
Response.Write "<p>姓名:" & name
Response.Write "<p>电话:" & tel
Response.Write "<p>email:" & email
Response.Write "<p>住址:" & home
Response.Write "<p>年龄:" & age
Response.Write "<p>简介:" & intro
Response.Write "<p><a href='add_form.htm'>返回,继续添加</a>"
End If
End If
%>

del
<%

If Trim(Request("name"))<>"" And Trim(Request("password"))<>"" Then

Dim strSql
strSql ="Delete From user Where name='" & Request("name") & "' And password='" & Request("password") & "'"
Dim number
db.Execute strSql,number
If number=0 Then
Response.Write "姓名或密码输入错误,找不到记录"
Else
Response.Write "<p align='center'>共有" & number & "条数据被删除"
End If
End If
%>

xianshi
<%

Dim rs,strSql
Set rs=Server.CreateObject("ADODB.Recordset")
strSql ="Select * From user Order By name "
rs.Open strSql,db,1


If rs.Bof Or rs.Eof Then
Response.Write "现在还没有数据"
Else
Do While Not rs.Eof '循环直到当前页结束或文件结尾

'下面将利用表格输出名单
Response.Write "<tr bgcolor='#E6E6E6' align='center'>"
Response.Write "<td>" & rs("name") & "</td>"
Response.Write "<td>" & rs("tel") & " </td>"
Response.Write "<td><a href='mailto:" & rs("email") & "'>" & rs("email") & "</td>"
Response.Write "<td>" & rs("home") & "</td>"
Response.Write "<td>" & rs("age") & "</td>"
Response.Write "<td>" & rs("intro") & "</td>"
Response.Write "</tr>"
rs.MoveNext
Loop
End If

rs.Close
Set rs=nothing
db.Close
Set db=nothing
%>

update
<%
'如果没有输入姓名,就不执行下列语句
If Trim(Request("name"))<>"" Then
Dim rs,strSql
strSql ="Select * From user Where name='" & Request("name") & "' And password='" & Request("password") & "'"
Set rs=db.Execute(strSql)
'查找匹配的记录,如果非空,就表示找到了。则引导至update_form.asp
If Not rs.Bof And Not rs.Eof Then
'这里用Session传递记录的id号,而不是在文件后跟参数,是为了安全考虑
Session("id")=rs("id")
Response.Redirect "update_form.asp"
Else
Response.Write "对不起,密码不正确,请重新输入"
End If
End If
%>
update_form
<%
Dim rs,strSql
'根据change.asp存放到Session里的id值,显示相应成员的信息
strSql ="Select * From user Where id=" & Session("id") 'id是数值,就不要加引号了
Set rs=db.Execute(strSql)
%>
<center>
<form method="post" action="update.asp">
<table border="0" width="80%" bgcolor="#E6E6E6">
<tr>
<td>姓名:</td><td><input type="text" name="name" size="20"
value="<%=rs("name")%>">**</td>
</tr><tr>
<tr>
<td>密码:</td><td><input type="password" name="password" size="20"
value="<%=rs("password")%>">**</td>
</tr><tr>
<td>电话:</td><td><input type="text" name="tel" size="20"
value="<%=rs("tel")%>"></td>
</tr><tr>
<td>email:</td><td><input type="text" name="email" size="40"
value="<%=rs("email")%>"></td>
</tr></tr>
<td>住址:</td><td><input type="text" name="home" size="40"
value="<%=rs("home")%>"></td>
</tr></tr>
<td>年龄:</td><td><input type="text" name="age" size="10"
value="<%=rs("age")%>"></td>
</tr><tr>
<td>简介:</td><td><textarea name="intro" rows="2" cols="40"
wrap="soft"><%=rs("intro")%></textarea></td>
</tr><tr>
<td></td><td><input type="submit" value=" 确 定 ">
<input type="reset" value=" 重 填 "> </td>
</tr>
<table>
</form>
</center>
<%
rs.Close
Set rs=nothing
db.Close
Set db=nothing
%>


<%
On Error Resume Next
If Trim(Request("name"))="" Or Trim(Request("password"))=""Then
Response.Write "对不起,姓名、密码必须输入"
Response.Write "<p><a href='update_form.asp'>返回,重新修改</a>"
Else
Dim name,password,tel,email,home,age,intro
name=Request("name")
password=Request("password")
tel=Request("tel")
home=Request("home")
email=Request("email")
age=Request("age")
intro=Request("intro")
'先将原有数据清除,再插入新的数据,为了安全,使用事务处理
db.BeginTrans '开始事务处理
Dim strSql
strSql="Delete From user Where id =" & Session("id")
db.Execute(strSql)
'再将数据填入数据库中
Dim sqla,sqlb
sqla = "Insert Into user(name,password"
sqlb = "Values('" & name & "','" & password & "'"
If tel<>"" Then
sqla = sqla & ",tel"
sqlb = sqlb & ",'" & tel & "'"
End If
If home<>"" Then
sqla = sqla & ",home"
sqlb = sqlb & ",'" & home & "'"
End If
If email<>"" Then
sqla = sqla & ",email"
sqlb = sqlb & ",'" & email & "'"
End If
If age<>"" Then
sqla = sqla & ",age"
sqlb = sqlb & "," & cInt(age)
End If
If intro<>"" Then
sqla = sqla & ",intro"
sqlb = sqlb & ",'" & intro & "'"
End If
strSql = sqla & ") " & sqlb & ")"
db.Execute(strSql)
If db.Errors.Count>0 Then
db.RollbackTrans '如有错误,取消事务处理结果
Response.Write "保存过程中发生错误,必须重新修改"
Response.Write "<p><a href='change.asp'>返回,重新修改</a>"
Else
db.CommitTrans '如无错误,提交事务处理结果
Response.Write "<h2 align='center'>您的信息已经安全修改,请牢记密码</h2>"
Response.Write "<p>姓名:" & name
Response.Write "<p>电话:" & tel
Response.Write "<p>email:" & email
Response.Write "<p>住址:" & home
Response.Write "<p>年龄:" & age
Response.Write "<p>简介:" & intro
Response.Write "<p><a href='change.asp'>返回,继续修改</a>"
End If
End If
%>

搜索更多相关主题的帖子: Microsoft asp strCon name 
2007-09-06 10:36
calcano
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-9-6
收藏
得分:0 
2007-09-06 19:32
孤独冷雨
Rank: 10Rank: 10Rank: 10
来 自:安徽滁州
等 级:贵宾
威 望:23
帖 子:1247
专家分:1909
注 册:2007-6-4
收藏
得分:0 
学习!

这里有男女系列成人用品,有时间兄弟们来看一看.
51za.
2007-09-06 21:10
sbypmqq
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-6-18
收藏
得分:0 
2007-09-09 22:11
威龙嘉少
Rank: 1
等 级:新手上路
帖 子:205
专家分:0
注 册:2007-9-24
收藏
得分:0 
哈哈,不错,不过好象中间少了些符号吧!
2007-09-25 11:35
快速回复:共同学习asp (简单的人员管理)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026297 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved