在线等~~大家帮我看看这段统计相加的代码错在哪里??

philipswmj 2009-07-10 04:00:05
<%
dim count,rs,rs1,i
set rs=server.CreateObject("ADODB.RecordSet")
rs.Source="select * from kaohe order by ID DESC"
rs.Open rs.Source,conn,1,1

for i=1 to 30
rs.movefirst
count=0
while not rs.eof
if (trim(rs("workid"))="1" or trim(rs("workid"))="11") and trim(year(rs("nianfen")))=2009 then count=count+1
rs.movenext
wend

set rs1=server.createobject("adodb.recordset")
sql="select * from kaohetongji where (id is null)"
rs1.open sql,conn,1,3
if rs1("workid")="" then
rs1.addnew
rs1("workid")=i
rs1("nianfen")=2009
rs1("tongji")=count
rs.update
else
sql="select * from kaohetongji where workid="&i
rs1.open sql,conn,3,3
rs1("tongji")=count
rs1.update
end if

rs1.close
set rs1=nothing
rs.close
set rs=nothing
i=i+1
next

rs1.close
set rs1=nothing
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
...全文
39 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
philipswmj 2009-07-14
  • 打赏
  • 举报
回复
错误类型:
Microsoft OLE DB Provider for SQL Server (0x80040E14)
列名 'count' 无效。
/gai_sql/admin/kaohetongji.asp, 第 24 行


这段代码,报错,并且更新这段好像不起作用?
toury 2009-07-10
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 philipswmj 的回复:]
for i=1 to 30

是循环统计30次.

workid :1 表示一个单位
2 表示一个单位

总共是30个单位.
[/Quote]
有点明白了,那我上面的搞错了,看这个

<%
dim count,rs,i

set rs=server.CreateObject("ADODB.RecordSet")

for i=1 to 30
'取单位相同的信息统计共有多少条
sql="SELECT COUNT(Id) FROM kaohe WHERE (workid="&i&" OR workid=11) AND nianfen LIKE '%2009%'"
count=conn.execute(sql)(0)
if count="" then count=0
err.clear
sql=""
'判断该单位是否已经存在于统计表内
set rs=conn.execute("SELECT workid FROM kaohetongji WHERE workid="&i)
if rs.eof and rs.bof then'如果不存在就写入新数据
sql="INSERT INTO kaohetongji (workid,nianfen,tongji) VALUES('"&i&"','"&2009&"','"&count&"')"
else'如果存在就更新其数据
sql="UPDATE kaohetongji SET tongji=count WHERE workid="&i
end if
if rs.state<>0 then rs.close
if sql<>"" then conn.execute(sql)

if err then'如果出错,提示并跳出循环
response.write"<script>alert('"&err.description&"')</script>"
exit for
end if
next
set rs=nothing
conn.close:set conn=nothing
%>

philipswmj 2009-07-10
  • 打赏
  • 举报
回复
for i=1 to 30

是循环统计30次.

workid :1 表示一个单位
2 表示一个单位

总共是30个单位.
toury 2009-07-10
  • 打赏
  • 举报
回复
8楼是疑问所在(上面漏了一个rs.movenext),这里是整理后的代码

<%
dim count,rs,i

'取你要的数字
sql="SELECT COUNT(Id) FROM kaohe WHERE (workid=1 OR workid=11) AND nianfen LIKE '%2009%'"
count=conn.execute(sql)(0)
if count="" then count=0
err.clear
set rs=server.CreateObject("ADODB.RecordSet")
sql="SELECT * FROM kaohe ORDER BY Id DESC"
rs.open sql,conn,1,1

for i=1 to 30'这个30是怎么回事?
'更新【kaohetongji】
sql="UPDATE kaohetongji SET workid=i,nianfen=2009,tongji=count WHERE workid='' OR workid IS NULL"
conn.execute(sql)
sql="UPDATE kaohetongji SET tongji=count WHERE workid="&i
conn.execute(sql)

if err then'如果出错,提示并跳出循环
response.write"<script>alert('"&err.description&"')</script>"
exit for
end if
rs.movenext
next
rs.close: set rs=nothing
conn.close:set conn=nothing
%>
toury 2009-07-10
  • 打赏
  • 举报
回复
我一段一段的问吧:

<%
dim count,rs,i'''''''''''''''''''''',rs1,i

'换个方式取你要的数字
sql="SELECT COUNT(Id) FROM kaohe WHERE (workid=1 OR workid=11) AND nianfen LIKE '%2009%'"
count=conn.execute(sql)(0)
if count="" then count=0
err.clear
set rs=server.CreateObject("ADODB.RecordSet")
''''''''''''''''''''''''''''''''set rs1=server.createobject("adodb.recordset")

'''''''rs.Source="select * from kaohe order by ID DESC"
'''''''rs.Open rs.Source,conn,1,1

sql="SELECT * FROM kaohe ORDER BY Id DESC"
rs.open sql,conn,1,1

for i=1 to 30'这个30是怎么回事?
''''''''''''rs.movefirst
''''''''''''count=0
''''''''''''while not rs.eof
''''''''''''if (trim(rs("workid"))="1" or trim(rs("workid"))="11") and trim(year(rs("nianfen")))=2009 then ''''''''''''count=count+1
''''''''''''rs.movenext
'''''''''''''wend



'''''''''''''''''''''''''' set rs1=server.createobject("adodb.recordset")'set放这里不是要创建30次?移出到循环外
''''''''sql="select * from kaohetongji where (id is null)"'这个是什么意思?
'''''''''rs1.open sql,conn,1,3
'''''''''if rs1("workid")="" then
'''''''''rs1.addnew
'''''''''rs1("workid")=i
'''''''''rs1("nianfen")=2009
''''''''''rs1("tongji")=count
''''''''''rs.update怎么UPDATE了rs??
'更新【kaohetongji】
sql="UPDATE kaohetongji SET workid=i,nianfen=2009,tongji=count WHERE workid='' OR workid IS NULL"
conn.execute(sql)
sql="UPDATE kaohetongji SET tongji=count WHERE workid="&i
conn.execute(sql)
'''''''''''else
''''''''''''sql="select * from kaohetongji where workid="&i
''''''''''''rs1.open sql,conn,3,3
''''''''''''rs1("tongji")=count
''''''''''''rs1.update
''''''''''''end if

''''''''''''rs1.close
''''''''''''set rs1=nothing
'''''''rs.close还在用啊,怎么在循环里面就关了呢
'''''''set rs=nothing还在用啊,怎么在循环里面就nothing了呢
''''''''i=i+1在for循环里怎么还i=i+1?是想隔一处理一条吗?
next

''''''''''''''''''''''rs1.close
''''''''''''''''''''''set rs1=nothing
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
philipswmj 2009-07-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 toury 的回复:]
除了上面红字问题,我觉得代码可能不是很合理。你把整段代码想实现什么功能大致说一下
[/Quote]

一共是两个表kaohe和kaohetongji。

Kaohe表结构: Id(序号) workid(单位编码) newsid(信息编号) nianfen(年份)
kaohetongji表结构:id(序号) workid(单位编码) nianfen(年份) tongji(单位编码相同情况下当年信息总数)

1、将考核过的信息的编号和单位编码存在Kaohe表里。
2、单位编码相同的信息统计共有多少条,然后将该单位统计的总数存在kaohetongji表中。
3、前台单位的编码直接调用kaohetongji表里的总条数。
toury 2009-07-10
  • 打赏
  • 举报
回复
除了上面红字问题,我觉得代码可能不是很合理。你把整段代码想实现什么功能大致说一下
toury 2009-07-10
  • 打赏
  • 举报
回复
你的数据库锁了,所以【超过了脚本运行的最长时间】
原因:
1、SQL语句有问题造成
2、记录集使用出现冲突造成
3、。。。
<%
dim count,rs,rs1,i
set rs=server.CreateObject("ADODB.RecordSet")
rs.Source="select * from kaohe order by ID DESC"
rs.Open rs.Source,conn,1,1

for i=1 to 30
rs.movefirst
count=0
while not rs.eof
if (trim(rs("workid"))="1" or trim(rs("workid"))="11") and trim(year(rs("nianfen")))=2009 then count=count+1
rs.movenext
wend

set rs1=server.createobject("adodb.recordset")
sql="select * from kaohetongji where (id is null)"
rs1.open sql,conn,1,3
if rs1("workid")="" then
rs1.addnew
rs1("workid")=i
rs1("nianfen")=2009
rs1("tongji")=count
rs.updaters???还是rs1
else
sql="select * from kaohetongji where workid="&i
rs1.open sql,conn,3,3
rs1("tongji")=count
rs1.update
end if

rs1.close
set rs1=nothing
rs.close
set rs=nothing
i=i+1
next

rs1.close
set rs1=nothing
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
%>
[/code]
philipswmj 2009-07-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 toury 的回复:]
SQL语句出问题了,
把语句打印出来放到数据库查询里走走,看什么问题
[/Quote]

SQL语句,试过了,没问题,请问能不能说的详细点??
longhuan 2009-07-10
  • 打赏
  • 举报
回复
SQL语句出问题了,
把语句打印出来放到数据库查询里走走,看什么问题
toury 2009-07-10
  • 打赏
  • 举报
回复
SQL语句出问题了,
把语句打印出来放到数据库查询里走走,看什么问题
philipswmj 2009-07-10
  • 打赏
  • 举报
回复
错误类型:
Active Server Pages, ASP 0113 (0x80004005)
超过了脚本运行的最长时间。可以为 Server.ScriptTimeOut 属性指定新值或更改 IIS 管理工具中的相应值来更改此限制。

28,406

社区成员

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

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