遇到情况了,help,急死了,程序一直出错。[asp+MsSQL]

dream520 2005-11-09 09:43:14
Dim conn,connstr
connstr = "Provider = Sqloledb; User ID = xxxx; Password = xxxxxx; Initial Catalog = xxxxxxxx; Data Source = 111.111.111.111;"
dim sql,rs,id
sql = "select id,num1,num2 from [table] order by id desc"
set rs = server.createobject("adodb.recordset")
conn.open connstr
rs.open sql,conn,1,1
do while not rs.eof
id = rs("id")
if rs("num2") < 3 and rs("num1") <> 10 then
sql = "update [table] set num3=5 where id="& id
conn.execute(sql)
else
sql = "update [table] set num3=2 where id="& id
conn.execute(sql)
end if
rs.movenext
loop
rs.close
conn.close
set rs = nothing
set conn = nothing


这段代码执行时应该是效率不行,数据库一共有9500多条记录,每次只能执行几千条就报错,错误信息不明,被服务器禁止显示了。我只有每次修改查询条件来更新所有记录,我想问一下,是不是因为这段代码效率太低?有没有高效的方法?谢谢
...全文
106 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxcooi 2005-11-11
  • 打赏
  • 举报
回复
汗!不要相信脚本的解释执行速度。写入存储过程更快。
dream520 2005-11-10
  • 打赏
  • 举报
回复
呵呵,谢了,我的sql没学过,只懂一点简直应用,所以只有用循环,谢谢你的查询语句
dream520 2005-11-10
  • 打赏
  • 举报
回复
真爽,1秒多一点就更新完所有记录了,呵呵
以前一分钟都搞不定
wanghui0380 2005-11-09
  • 打赏
  • 举报
回复
1. update [table] set num3=5 where num2<3 and num1<>10
2. update [table] set num3=2 where not(num2<3 and num1<>10)
wanghui0380 2005-11-09
  • 打赏
  • 举报
回复
不太明白,你为什么要用循环,直接两条sql语句不就成了嘛!

1. update [table] set num3=5 where num2<3 and num1<>10
2. update [table] set num3=5 where not(num2<3 and num1<>10)
  • 打赏
  • 举报
回复
“错误信息不明,被服务器禁止显示了”--有这种事?是不是你的“显示有好http错误”打开了?
tylchina 2005-11-09
  • 打赏
  • 举报
回复
用Command执行试过吗?Command是专门设计用来执行命令的
......................................................................
objCmd=Server.CreateObject("ADODB.Command")
objCmd.ActiveConnection=conn
objCmd.CommandType=1
do while not rs.eof
id = rs("id")
if rs("num2") < 3 and rs("num1") <> 10 then
sql = "update [table] set num3=5 where id="& id
else
sql = "update [table] set num3=2 where id="& id
end if
objCmd.CommandText=sql
objCmd.Execute
rs.movenext
loop
Set objCmd=Nothing

28,406

社区成员

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

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