ASP循环数组元素出错
keywArr=split(keyw,",")fori=0toubound(keywArr)tit=keywArr(i)'xx=conn.execute("selecti...
keywArr=split(keyw,",")
for i=0 to ubound(keywArr)
tit=keywArr(i)
'xx=conn.execute("select id,tit from tags where tit='"&tit&"'")(0)
readList=readList&"<a href=search-"&xx&".html>"&tit&"</a> | "
next
这段代码不知道哪里错了,请达人帮我。其中注释掉的部分删除后正常,但我需要那个id故不能删除。另外,如果修改成
xx=conn.execute("select id,tit from tags")(0)
xx=conn.execute("select id,tit from tags where id=1")(0)
xx=conn.execute("select id,tit from tags where tit='PS'")(0)等都是正常的。且这个变量tit也是真实有效的(有输出文字部分)。加cStr也无效………………
下面这个是不是也是相同原因造成?http://zhidao.baidu.com/question/301414114.html
上面打错了,for i=0 to ubound(keywArr)-1 展开
for i=0 to ubound(keywArr)
tit=keywArr(i)
'xx=conn.execute("select id,tit from tags where tit='"&tit&"'")(0)
readList=readList&"<a href=search-"&xx&".html>"&tit&"</a> | "
next
这段代码不知道哪里错了,请达人帮我。其中注释掉的部分删除后正常,但我需要那个id故不能删除。另外,如果修改成
xx=conn.execute("select id,tit from tags")(0)
xx=conn.execute("select id,tit from tags where id=1")(0)
xx=conn.execute("select id,tit from tags where tit='PS'")(0)等都是正常的。且这个变量tit也是真实有效的(有输出文字部分)。加cStr也无效………………
下面这个是不是也是相同原因造成?http://zhidao.baidu.com/question/301414114.html
上面打错了,for i=0 to ubound(keywArr)-1 展开
展开全部
这是我的测试代码
你看看
<!--#include file="conn.asp" -->
<%
on error resume next
keyw = "腾讯,新浪,百度,人人"
keywArr=split(keyw,",")
for i=0 to ubound(keywArr)
tit=keywArr(i)
xx=conn.execute("select NewsUrl,Title from News where Title='"&tit&"'")(0)
if err=0 then
readList=readList&"<a href="&xx&">"&tit&"</a> | "
end if
next
response.Write(readlist)
conn.close
set conn = nothing
%>
你错在当tit在数据库中不存在时读不出数据的,就会出错,所以要加上on error resume next并且捕获错误,然后再输出 ,不出错的情况下error=0
你看看
<!--#include file="conn.asp" -->
<%
on error resume next
keyw = "腾讯,新浪,百度,人人"
keywArr=split(keyw,",")
for i=0 to ubound(keywArr)
tit=keywArr(i)
xx=conn.execute("select NewsUrl,Title from News where Title='"&tit&"'")(0)
if err=0 then
readList=readList&"<a href="&xx&">"&tit&"</a> | "
end if
next
response.Write(readlist)
conn.close
set conn = nothing
%>
你错在当tit在数据库中不存在时读不出数据的,就会出错,所以要加上on error resume next并且捕获错误,然后再输出 ,不出错的情况下error=0
展开全部
改为:
xx=conn.execute("select id,tit from tags where tit="&tit&")(0)
另外,用split函数时,数组要定义成动态数组
xx=conn.execute("select id,tit from tags where tit="&tit&")(0)
另外,用split函数时,数组要定义成动态数组
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
keywArr=split(keyw,",")
for i=0 to ubound(keywArr)
tit=keywArr(i)
xx=conn.execute("select top 1 id,tit from tags where tit='"&tit&"'")(0)
readList=readList&"<a href=search-"&xx&".html>"&tit&"</a> | "
next
for i=0 to ubound(keywArr)
tit=keywArr(i)
xx=conn.execute("select top 1 id,tit from tags where tit='"&tit&"'")(0)
readList=readList&"<a href=search-"&xx&".html>"&tit&"</a> | "
next
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询