asp如何循环读取一张表把数据插入另一张表
如上图所示,如何用ASP循环A表,根据ID把A1+...+A5插入到B表ID相等的SumA字段,用的是ASP,求大神们帮忙,急等!...
如上图所示,如何用ASP循环A表,根据ID把A1+...+A5插入到B表ID相等的SumA字段,用的是ASP,求大神们帮忙,急等!
展开
2个回答
展开全部
A表循环的时候写入B表:
<%
Set rs_a = Server.CreateObject("ADODB.Recordset")
sql="select * from A表 order by id asc" '顺序从小到大
rs_a.open sql,conn,1,1
if not rs_a.eof then
'循环读写开始========================== A表rs_a,B表rs_b =====
do while not rs_a.eof
Set rs_b = Server.CreateObject("ADODB.Recordset")
sql="select * from B表"
rs_b.open sql,conn,1,3
rs_b.addnew
rs_b("Name")= rs_a("Name")
rs_b("A1")= rs_a("A1")
rs_b("A2")= rs_a("A2")
rs_b("A3")= rs_a("A3")
rs_b("A4")= rs_a("A4")
rs_b("A5")= rs_a("A5")
rs_b.update
rs_b.close
set rs_b=nothing
rs_a.movenext
loop
'循环读写结束==========================
else
response.write ("A表没有数据")
end if
rs_a.close
set rs_a=nothing
%>
<%
Set rs_a = Server.CreateObject("ADODB.Recordset")
sql="select * from A表 order by id asc" '顺序从小到大
rs_a.open sql,conn,1,1
if not rs_a.eof then
'循环读写开始========================== A表rs_a,B表rs_b =====
do while not rs_a.eof
Set rs_b = Server.CreateObject("ADODB.Recordset")
sql="select * from B表"
rs_b.open sql,conn,1,3
rs_b.addnew
rs_b("Name")= rs_a("Name")
rs_b("A1")= rs_a("A1")
rs_b("A2")= rs_a("A2")
rs_b("A3")= rs_a("A3")
rs_b("A4")= rs_a("A4")
rs_b("A5")= rs_a("A5")
rs_b.update
rs_b.close
set rs_b=nothing
rs_a.movenext
loop
'循环读写结束==========================
else
response.write ("A表没有数据")
end if
rs_a.close
set rs_a=nothing
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询