ASP编程如何将同一数据库多条记录显示,并可同时修改(只需设置一键提交全部修改,不需逐条保存)

ASP编程如何将同一数据库多条记录显示,并可同时修改(只需设置一键提交全部修改,不需逐条保存),第1张

我给你个我今天编写的程序吧

你看了自己照着改就可以了<%id=request("id")

xztype=trim(request("xztype"))

if id<>"" and xztype<>"" then

id=int(id)

%>

<table width="100%" border="1" align="center" bordercolor="cccccc">

<form action="bxfl2save.asp" method="post">

<tr align="center" bgcolor="#CCCCCC">

<td height="27">性别</td>

<td>年龄</td>

<td>保险金额</td>

<td>缴费期限<input type="hidden" name="idd" value="<%=id%>">

<input type="hidden" name="xztype" value="<%=xztype%>"></td><td>保费</td>

</tr>

<%sql="select * from bftable where xztype='"&xztype&"' and idd="&id

rs.open sql,conn,1,3

if rs.recordcount=0 then

rs.close

response.write"<tr><td colspan=5><a href=bxfl.asp>请先添加保费后再修改保费</a></td></tr>"

response.end

else

soon=rs.recordcount

do while not rs.eof

i=i+1

if i=2 then

i=0

end if

if i=1 then

xx=""

end if

if i=0 then

xx="bgcolor=#cccccc"

end if

%>

<tr align="center" <%=xx%>>

<td height="27"><input name=id type="hidden" value="<%=rs("id")%>"><select name="sex" size="1" id="sex">

<option value="男" <%if trim(rs("sex"))="男" then

response.write " selected "

end if%>>男</option>

<option value="女" <%if trim(rs("sex"))="女" then

response.write " selected "

end if%>>女</option>

</select>

</td>

<td><input name="age" id="age" size="15" value="<%=trim(rs("age"))%>"></td>

<td><input name="bxmoney" id="bxmoney" size="15" value="<%=trim(rs("bxmoney"))%>"></td>

<td><input name="jfterm" id="jfterm" size="15" value="<%=trim(rs("jfterm"))%>"></td>

<td><input name="bf" size="15" value="<%=trim(rs("bf"))%>"></td>

</tr>

<%rs.movenext

loop

soon=i+1

if (soon mod 2)=0 then

xx="bgcolor=#cccccc"

else

xx=""

end if

end if

response.write"<tr "&xx&"><td colspan=5 height=27 align=center><input type=submit name=Submit value=确定 /></td></tr>"

%></form>

</table>

<%else

end if%>

上面是显示多条记录

下面是修改多条记录

<%

id=request("id")

idd=request("idd")

xztype=request("xztype")

sex=request("sex")

age=request("age")

bxmoney=request("bxmoney")

jfterm=request("jfterm")

bf=request("bf")

sex=split(sex,",")

for i = 0 to ubound(sex)

sex(i)=sex(i)

next

age=split(age,",")

for i = 0 to ubound(age)

age(i)=age(i)

next

bxmoney=split(bxmoney,",")

for i = 0 to ubound(bxmoney)

bxmoney(i)=bxmoney(i)

next

jfterm=split(jfterm,",")

for i = 0 to ubound(jfterm)

jfterm(i)=jfterm(i)

next

bf=split(bf,",")

for i = 0 to ubound(bf)

bf(i)=bf(i)

next

id=split(id,",")

for i = 0 to ubound(id)

id(i)=id(i)

next

for i=0 to ubound(bf)

if sex(i)<>"" or age(i)<>"" or bxmoney(i)<>"" or jfterm(i)<>"" or bf(i)<>"" then

sql="select * from bftable where id="&trim(id(i))

rs.open sql,conn,1,3

rs("sex")=trim(sex(i))

rs("age")=trim(age(i))

rs("bxmoney")=trim(bxmoney(i))

rs("jfterm")=trim(jfterm(i))

rs("bf")=trim(bf(i))

rs.update

rs.close

end if

next

%>

只要表单的中的多条记录控件的name是一样的 那可以用for i=1 to request.Form("id").count来循环对每一条记录进行 *** 作

例子:

for i=1 to request.form("id").count

id=request.Form("id")(i)

...

...

对数据库进行 *** 作

next


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/10646508.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-10
下一篇 2023-05-10

发表评论

登录后才能评论

评论列表(0条)

保存