日期:2014-05-17  浏览次数:20772 次

asp初学,请教向数据库中增加记录的问题
<!--#include   file=rsconn.asp-->

<%
response.write( " <table   border=1   width=100%   id=table1> <tr> <td> 姓名 </td> <td> 学号 </td> <td> 性别 </td> </tr> ")
set   rs=server.CreateObject( "adodb.recordset ")  
sqlstr= "select   *   from   实验名单 "  
rs.open   sqlstr,conn,1,3
if   request( "flag ")=1   then  
'------------------添加新记录-------------
rs.addnew  
rs( "姓名 ")= "王二 "  
rs( "学号 ")= "2004103856 "
rs( "性别 ")= "女 "
rs.update  
'-----------------------------------------
end   if
rs.movefirst
while   not   rs.eof
response.write( " <tr> ")
response.write( " <td> ")
response.write(rs( "姓名 "))
response.write( " </td> ")  
response.write( " <td> ")
response.write(rs( "学号 "))
response.write( " </td> ")  
response.write( " <td> ")
response.write(rs( "性别 "))
response.write( " </td> ")  
response.write( " </tr> ")
rs.movenext
wend
response.write( " </table> ")
rs.close  
conn.close  
set   rs=nothing  
set   conn=nothing  
%>
</script>
<html>
<head>
<meta   http-equiv= "Content-Language "   content= "zh-cn ">
</head>
<body>
<form   method= "post ">
<input   type= "submit "   name= "addnew "   value= "添加 "   >
<input   type= "button "   name= "delete "   value= "删除 ">
</form>
</body>
</html>

我希望按下按钮以后,向数据库中添加记录,但客户端代码不能使用redirect,应该怎么修改一下,谢谢!

------解决方案--------------------
<!--#include file=rsconn.asp-->
<%
flag=clng(request( "flag "))
select case flag
case 0
%>
</script>
<html>
<head>
<meta http-equiv= "Content-Language " content= "zh-cn ">
</head>
<body>
<form method= "post ">
<input type= "hidden " name= "flag " value=1>
<input type= "submit " name= "addnew " value= "添加 " >
<input type= "button " name= "delete " value= "删除 ">
</form>
</body>
</html>
<%
case 1
response.write( " <table border=1 width=100% id=table1> <tr> <td> 姓名 </td> <td> 学号 </td> <td> 性别 </td> </tr> ")
'------------------添加新记录-------------
sql= "insert into 实验名单 (姓名,学号,性别) value ( '王二 ', '2004103856 ' '女 ') "
conn.execute sql
'-----------------------------------------
set rs=server.CreateObject( "adodb.recordset ")
sql= "select 姓名,学号,性别 from 实验名单 order by 学号 "
rs.open sql,conn,1,1
if rs.recordcount <> 0 then
while not rs.eof
name=rs( "姓名 ")
n