首页 > 开发 > Asp > 正文

asp中用insert into语句向数据库插入记录的方法

2019-10-20 15:23:21
字体:
来源:转载
供稿:网友
asp中用insert into语句向数据库插入记录信息的方法,学习的朋友可以参考下。
一、'建立register.asp

<%@ language=vbscript %>
<html >
<head>
<title>注册页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
td img {display: block;}.STYLE2 {font-size: 12px}
.STYLE3 {
color: #FF0000;
font-weight: bold;
font-size: 16px;
}
</style>
</head>
<body bgcolor="#ffffff">
<table width="531" border="0" align="center" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<!-- fwtable fwsrc="未命名" fwbase="register.jpg" fwstyle="Dreamweaver" fwdocid = "1502317357" fwnested="0" -->
<tr>
<td width="58" rowspan="5" valign="top" bgcolor="#D8FBB5"><img src="spacer.gif" width="58" height="1" border="0" border="0" src="/uploads/allimg/130108/132S634L-0.jpg" />

asp中用insert into语句向数据库插入记录的方法
这时打开数据表user会看到:
asp中用insert into语句向数据库插入记录的方法
说明操作成功,因为已经提交两次,所以我们看到表中插入了两条新的记录,但是表中出现了重复记录,以下在result2.asp中添加代码予以解决:

<%@ language=vbscript %>
<!-- #include file="con1.asp"-->

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>注册成功</title>
<style type="text/css">
<!--
.STYLE1 {font-size: 24px}
-->
</style>
<br></head><body>
<%
'建立recordset对象方法
set rst=server.createobject("adodb.recordset")
rst.open"select * from user where u_user='"&request.form("u_user") & "'",conn,1,1
if rst.recordcount>0 then
response.write"用户名:"&request.form("u_user")&"已被占用,请点击返回重新注册"
%>
<a href="register.asp" class="STYLE1">返回重新注册</a>
<%
response.End
else
set rst1=conn.execute("insert into user (u_user,u_pass) values('"&request.form("u_user")&"','"&request.form("u_pass")&"')")
end if
%>
<table width="300" border="0" align="center">
<tr>
<td align="center"><img src="chenggong.jpg" alt="注册成功" width="297" height="201"></td>
</tr>
<tr>
<td align="center"><a href="register.asp" class="STYLE1">返回</a></td>
</tr>
</table>
</body>
</html>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表