如何同时修改并保存多条记录?(access库)

ready 2001-06-04 05:15:00
...全文
277 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
ready 2001-06-13
  • 打赏
  • 举报
回复
请教zjtn(梦居士)
编辑页:
Response.Write "<form method=post action=save.asp>"
while not rs.eof
Response.Write rs("id")
if rs("report_form") = "" then
Response.Write "<input type=checkbox name=dd value=是>"
else
Response.Write "<input type=checkbox name=dd checked value=是>"
end if
Response.Write "<br>"
Response.Write "<input type=hidden name=id value=" & rs("id") & ">"
rs.movenext
wend
Response.Write "<input type=submit value=submit>"
Response.Write "</form>"
保存页:
for i= 0 to request.form("id").count - 1
id = request("id")(i)
content = Request.Form("dd")(i)
sql = "update shenpi set report_form = '"&content&"' where id = "&id&""
cn.execute(sql)
next
Response.Redirect "default.asp"
为什么会出现数组索引越界错误?
ready 2001-06-13
  • 打赏
  • 举报
回复
就象我上面那个那样,希望能帮我测试一下,thank you very much!
ready 2001-06-13
  • 打赏
  • 举报
回复
我开始也用的for i = 1 to request.form("id").count,它对text这样类型可以,但对checkbox就不行了.
zjtn 2001-06-13
  • 打赏
  • 举报
回复
对不起,是我考虑不周
原来的
for i=0 to request.form("id").count-1
应该该为
for i=1 to request.form("id").count

可能是因为ASP对数组的解析问题
ready 2001-06-12
  • 打赏
  • 举报
回复
多谢zjtn(梦居士)!
zjtn 2001-06-12
  • 打赏
  • 举报
回复
很简单啦!
其实是你自己先犯了一个错误
response.write "<form method=post action=save.asp>"
while not rs.eof
response.write "<input name=test value=" & rs("content") <------这里错了
response.write "<input typ=hidden name=id value=" & rs("id") & ">"
rs.movenext
wend
response.write "</form>"

你这里对多条纪录只用了一个from,而在同一个From里,你每一条纪录的Content字段,都用的name为test,这样,每一条纪录的content提交的时候,服务器端会收到一个纪录的Content的集合,你再用save.asp,把每一个ID纪录的content字段都更新为收到的这一个Content集合的第一个数据。当然会一样了。
更改如下:
save.asp:
Dim id,content,sql '<------养成好习惯
for i=0 to request.form("id").count-1 '<------ 这里是不是应该改成这样?你自己看吧!
id = request("id")(i)
content = request("test")(i) '<------这里同样是取test集合里的数据
sql = sql & " update tabname set colname = '" & content & "' where id = " & id & " " '<------这里你可以把所有的更新语句组合,一次更新,减小服务器负荷
next
cn.execute(sql) '<------最后再执行

sinokid 2001-06-12
  • 打赏
  • 举报
回复
ID = Split(Request("id"),",")

For i=0 to Ubound(ID)
sql = "update tabname set colname = 'content' where id = "&ID(i)&""
Conn.execute(sql)
Next
ready 2001-06-12
  • 打赏
  • 举报
回复
楼上,你这个程序为什么修改并保存记录之后,每条记录的结果都成了一样的内容了?到底错在哪里?
songzx66 2001-06-11
  • 打赏
  • 举报
回复
response.write "<form method=post action=save.asp>"
while not rs.eof
response.write "<input name=test value=" & rs("content")
response.write "<input typ=hidden name=id value=" & rs("id") & ">"
rs.movenext
wend
response.write "</form>"

save.asp:
for i=1 to request.form("id").count
id = request("id")(i)
sql = "update tabname set colname = 'content' where id = "&id&""
cn.execute(sql)
next
ready 2001-06-11
  • 打赏
  • 举报
回复
我想这样写是否可以
response.write "<form method=post action=save.asp>"
while not rs.eof
response.write "<input name=test value=" & rs("content")
response.write "<input typ=hidden name=id value=" & rs("id") & ">"
rs.movenext
wend
response.write "</form>"

save.asp:
id = request("id")
sql = "update tabname set colname = 'content' where id = "&id&""
cn.execute(sql)
tripofdream 2001-06-05
  • 打赏
  • 举报
回复
???什么意思?
ready 2001-06-05
  • 打赏
  • 举报
回复
我说的多条记录是同一个字段下的多条记录.
zjtn 2001-06-05
  • 打赏
  • 举报
回复
楼上这位朋友的方法固然可以实现,但是太耗费资源,除非你用批量更新。
我想对ready说的是,楼上几位老兄说的没有错,是你理解错了。说明如下:
并不是一次SQL语句的执行,只能有一个动作,例如:我要进行两条纪录的更新,我可以把两条更新SQl语句写在一起,然后让ADO提交执行,数据库就会按顺序执行两条语句
Update tabname set colname1='xxx',colname2='yyy'where ID=1 Update tabname set colname1='zzz' where ID=2

两条语句之间只要有空格,数据库就会识别。按顺序两条执行。
提醒一下,上面说的方法,只适合用Connection的Execute(SQL)方法,而对recordset的更新,我建议你看一看批次更新。
friends 2001-06-05
  • 打赏
  • 举报
回复
i=0
do while not rs.eof
rs("field1")=content(i)
rs.update
rs.movenext
i=i+1
loop
'ok 这回搞定了
happy7 2001-06-05
  • 打赏
  • 举报
回复
你晕了
我也晕了
gooyan 2001-06-04
  • 打赏
  • 举报
回复
用sql语句
qianhb 2001-06-04
  • 打赏
  • 举报
回复
使用SQL语句
with query1 do begin
with sql do
begin
clear;
add('update 表 SET 字段=值');
end;
applyupdate;
end;
redcoral 2001-06-04
  • 打赏
  • 举报
回复
用SQL语句不就可以了吗?

比如:

strSQl = strSQl & "Update UpdateTable Set Field1='',Field2='' Where Field1='Hello'"

DbConn.Exeute(strSql)

不就可以了吗?^_^

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧