ASP批量更新出错(用数组方法)
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("db1.mdb")
%>
<%
exec="select * from chengji"
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
%>
<style type="text/css">
<!--
.STYLE1 {
color: #FF0000;
font: 12;
}
-->
</style>
<style type="text/css">
<!--
.STYLE2 {
color: #993333;
font-size: 12px;
}
.STYLE3 {
color: #0000FF;
font-weight: bold;
font-size: 16px;
}
-->
</style>
<title>学生成绩修改</title>
<div align="center" class="STYLE3">学生成绩修改</div>
<form action="a1.asp" method="post" name="form1">
<table width="100" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="30" height="20" class="STYLE2"><div align="center">序号</div></td>
<td width="40" class="STYLE2"><div align="center">姓名</div></td>
<td width="30" class="STYLE2"><div align="center">语文</div></td>
</tr>
<%do while not rs.eof%>
<tr>
<td class="STYLE1"><div align="center"><%=rs("id")%>
<input name="id" type="hidden" value="<%=rs("id")%>"> </div></td>
<td class="STYLE1"> <div align="center"> <%=rs("Name")%> </div></td>
<td > <div align="center">
<input name="yuwen<%=rs("id")%>" type="text" id="yuwen" value="<%=rs("yuwen")%>" size="3" class="STYLE2" >
</div>
</td>
</tr>
<%
rs.movenext
loop
%>
</table>
<label>
<div align="center">
<input type="submit" name="Submit" value="提交">
</div>
</label>
</form>
执行页代码:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("db1.mdb")
%>
<%
dim id
id=request("id") '获取的ID值如: id=1,3
nid=split(id,", ") ' 根据逗号把id分割,返回数组nid
sid=ubound(nid) '得到几个值
for i = 0 to sid 'nid(i)就是要操作的id,并做循环更新记录
set rs=server.CreateObject("adodb.recordset")
sql="select * from chengji where id='"&nid(i)&"'"
rs.open sql,conn,1,3
rs("yuwen")=request("yuwen"&nid(i))
rs.update
rs.close
set rs=nothing
next
%>
数据库:db1.mdb 结构:表chenji 数段 :id name yuwen shuxue yingyu