我刚刚继承了一个用经典ASP编写的古老网站。短期内需要立即更新网站(尽管他们准备在几个月内推出一个全新的网站)。
这些年来,代码有点混乱。我没有这种语言的先验知识,但我得到了要点,主要页面调用.asp包括所有这些。大多是直截了当的。我的工作是更新一些时间表和地图。当我遇到后者的问题时,我几乎到了终点,在这个页面上,我得到的似乎是数据库错误:
http://test.bigbluebus.com/busroutes/map/index.asp?routeid=1010
这应显示类似于以下链接的信息(尽管显然是路线10而不是路线7):
http://test.bigbluebus.com/busroutes/map/index.asp?routeid=77
我遇到的问题是:“路线”10线正在变为“快速”10线。现有的命名约定 - 或者至少是它们用于为路由提供ID的约定,是使用常规线路/路由的路由号码,并使用重复的号码来表示快速路由。例如,Route 7使用ID“7”,而Rapid 7使用ID“77”。考虑到这一点,我分配了路线10的快速版本,ID为“1010”。这对于时间表(位于左栏中的链接)非常有效。
但很明显,这些地图正在分崩离析。我从我能想到的每个角度看过它,我不知道是什么原因引起了这个问题。但由于我对ASP一无所知,这并不奇怪。
我将“快速10”左列链接链接到routeid 1010,并在index.asp的第151行链接到我只是更改了:
<% if introuteid <> 33 AND introuteid <> 77 AND introuteid <> 111 then %>
到
<% if introuteid <> 33 AND introuteid <> 77 AND introuteid <> 111 AND introuteid <> 1010 then %>
只需在字符串中添加1010(如果这就是你所谓的那个......对新手,朋友和邻居温柔一点)似乎正在处理快速线条。如果你必须笑,但这种技术到目前为止已经奏效了! ;)
使用以上链接来快速&amp;作为一个工作的例子,任何人都可以告诉我为什么Rapid 10不工作?它是以某种方式从数据库(我无法访问)中获取此地图信息吗?
非常感谢任何指导。哦是的,明天是我的截止日期。杯。
以下是该页面的完整代码 - 它仅在1010(快速10)中断:
<%
Option Explicit
%>
<% if Request.QueryString("routeid") = "" or not (IsNumeric(Request.QueryString("routeid"))) or Request.QueryString("routeid")=11 then
response.Redirect "../index.asp"
else
dim introuteid
set introuteid=request.QueryString("routeid")
end if%>
<!-- #include file="../../datastore.asp" -->
<% dim m
m=2
dim param%>
<%
dim position, line, dayofweek
position="map"
line=introuteid
dayofweek=""
%>
<script language="javascript">
function winopen(urlname, winname, feature) {
window.open(urlname, winname, feature);
}
</script>
<html>
<head>
<title>Welcome to the Big Blue Bus</title>
</head>
<body background="../../_images/common/bbb_site_bckgd_1800x000.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="744" border="0" cellspacing="0" cellpadding="0" height="100%" valign="baseline" align="left">
<tr>
<td colspan="2" width="744" valign="top">
<!-- #include file="../lib/header.asp" -->
</td>
</tr>
<tr>
<td width="176" height="100%" valign="top">
<!-- #include file="../../lib/busroutelefthandbar.asp" -->
</td>
<td width="501" valign="top" align="left">
<table width="501" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td colspan="3">
<font face=<%=application("face_primary")%> size=<%=application("size_large")%> color=<%=application("Color_title")%> >
<b>Line Map</b><br>
</font>
<% if introuteid = 7 then %>
<!--<img src="../../_images\new_images\super7.gif" border="0">--><br>
<% elseif introuteid = 10 then %>
<!--<img src="../../_images\new_images\10express.gif" border="0"><br><br> -->
<% elseif introuteid = 0 then %>
<img src="../../_images\new_images\super12.gif" border="0"><br><br>
<% elseif introuteid = 33 then %>
<img src="../../_images\new_images\rapid3Icon.gif" border="0"><br>
<% elseif introuteid = 77 then %>
<img src="../../_images\new_images\rapid7Icon.gif" border="0"><br>
<% elseif introuteid = 1010 then %>
<img src="../../_images\new_images\rapid10Icon.gif" border="0"><br>
<% end if %>
<%' if introuteid = 0 or introuteid = 2 or introuteid = 9 or introuteid = 10 or introuteid = 11 or introuteid = 14 then %>
<!-- <font face=<%'=application("face_primary")%> size=<%'=application("size_primary")%>>
Effective September 8, 2002<br><br>
</font> -->
<%' end if %>
</td>
</tr>
<%Dim objCommand5, objRs0
Set objCommand5 = Server.CreateObject("ADODB.Command")
objCommand5.ActiveConnection = strConnect
objCommand5.CommandText = "select name "&_
"from tblbusroute "&_
"where routeid = ?"
objCommand5.CommandType = adCmdText
Set param = objCommand5.CreateParameter("routeid", adInteger, adParamInput, 4, trim(request.querystring("routeid")))
objCommand5.Parameters.Append(param)
Set objRS0 = objCommand5.Execute
'Set objCommand5 = Nothing%>
<tr>
<td colspan="3">
<table width="507" border="1" cellspacing="0" cellpadding="0" bordercolor=<%=application("bgcolor")%>>
<tr>
<td bgcolor=<%=application("bgcolor")%> >
<font face=<%=application("face_primary")%> size=<%=application("size_large")%> color=<%=application("Color_white")%> >
<b> <%=objRS0("name")%></b>
</font>
<% Set objRS0 = Nothing %>
</td>
</tr>
<tr>
<td>
<table width="507" border="0" cellspacing="2" cellpadding="4">
<tr>
<td valign="center" width="50%"n bgcolor=<%=application("Color_lightblue")%>>
<font valign="center" face=<%=application("face_primary")%> size=<%=application("size_primary")%>>
<center>DETAILED INFORMATION</center>
</font>
</td>
<td valign="center" width="50%" bgcolor=<%=application("Color_lightblue")%>>
<font face=<%=application("face_primary")%> size=<%=application("size_primary")%>>
<center>SCHEDULE</center>
</font>
</td>
</tr>
<tr>
<td valign="top">
<font face=<%=application("face_primary")%> size=<%=application("size_secondary")%>>
<center><b><a href="../location/index.asp?routeid=<%=introuteid%>">Stop Locations</b></a> | Map | <a href="../destination/index.asp?routeid=<%=introuteid%>">Destinations</a></center>
</font>
</td>
<td width="52%" valign="top" align="left">
<font face=<%=application("face_primary")%> size=<%=application("size_secondary")%>>
<center><a href="../../busroutes/schedule.asp?bus_route=<%=introuteid%>&dayofweek=weekdays">Monday-Friday</a> | <a href="../../busroutes/schedule.asp?bus_route=<%=introuteid%>&dayofweek=saturday">Saturday</a> | <a href="../../busroutes/schedule.asp?bus_route=<%=introuteid%>&dayofweek=sunday">Sunday/Holidays</a></center>
</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
<!-----------end of bus routes navigations--------------->
<!----------beginning of Stop Loacation--------------------->
<tr>
<td valign="top" width="222">
<% if introuteid <> 33 AND introuteid <> 77 AND introuteid <> 111 AND introuteid <> 1010 then %>
<table width="212" border="0" cellspacing="0" cellpadding="0" bordercolor=<%=application("bgcolor")%>>
<tr>
<td>
<font face=<%=application("face_primary")%> size=<%=application("size_large")%> color=<%=application("Color_title")%> >
<b>Places to Go</b>
</font>
</td>
</tr>
<tr>
<td>
<table border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="46%" valign="top">
<font face=<%=application("face_secondary")%> size=<%=application("size_secondary")%> color="red"><b>*</b></font>
<font face=<%=application("face_primary")%> size=<%=application("size_primary")%>>indicates closest service to destination<br></font>
</td>
</tr>
<%Dim objRs6
Set objCommand5 = Server.CreateObject("ADODB.Command")
objCommand5.ActiveConnection = strConnect
objCommand5.CommandText = "select tblplace.placeid as placeid, "&_
"tblplace.name as name, "&_
"tblplace.address as address, "&_
"tblplace.zip as zip, "&_
"tblplace.phone as phone, "&_
"tblplace.description as description, "&_
"tbl_places_to_go_category.categoryname as categoryname, "&_
"tbl_places_to_go_category.placestogocategoryid as placestogocategoryid, "&_
"tblplace_busroute.closeroute as closeroute "&_
"from tblplace, tbl_places_to_go_category, tblplace_busroute "&_
"where tblplace_busroute.routeid = ? "&_
"and tblplace_busroute.placeid=tblplace.placeid and "&_
"tblplace.placestogocategoryid=tbl_places_to_go_category.placestogocategoryid "&_
"order by placestogocategoryid, name"
objCommand5.CommandType = adCmdText
Set param = objCommand5.CreateParameter("routeid", adInteger, adParamInput, 4, trim(request.querystring("routeid")))
objCommand5.Parameters.Append(param)
Set objRS6 = objCommand5.Execute
Set objCommand5 = Nothing%>
<% dim strcompareCategory
strcompareCategory=""%>
<% dim strcomparename
strcomparename=""%>
<%while not objRS6.eof%>
<%if strcompareCategory<>"" and strcompareCategory <> trim(objRS6("categoryname")) then%>
</td>
</tr>
<%end if%>
<% if strcompareCategory="" or trim(strcompareCategory) <> trim(objRS6("categoryname")) then%>
<tr>
<td valign="center" width="50%">
<br><font face=<%=application("face_primary")%> size=<%=application("size_primary")%> color=<%=application("Color_title")%>>
<b><%=objRS6("categoryname")%></b>
</font>
<%strcompareCategory = trim(objRS6("categoryname"))%>
</td>
</tr>
<tr>
<td width="46%" valign="top">
<font face=<%=application("face_primary")%> size=<%=application("size_primary")%>>
<a href="javascript:winopen('placestogodetail.asp?placeid=<%=trim(objRS6("placeid"))%>','glossarywindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=400,height=400,top=20,left=20')">
<%=objRS6("name")%></a><% if trim(objRS6("closeroute")) = "yes" then%><font face=<%=application("face_secondary")%> size=<%=application("size_secondary")%> color="red"><b>*</b></font><%end if%><br>
</font>
<% strcomparename = objRS6("name")%>
<%else%>
<% if strcomparename <> objRS6("name") then%>
<font face=<%=application("face_primary")%> size=<%=application("size_primary")%>>
<a href="javascript:winopen('placestogodetail.asp?placeid=<%=trim(objRS6("placeid"))%>','glossarywindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=400,height=400,top=20,left=20')">
<%=objRS6("name")%></a><% if trim(objRS6("closeroute")) = "yes" then%><font face=<%=application("face_secondary")%> size=<%=application("size_secondary")%> color="red"><b>*</b></font><%end if%><br>
</font>
<%strcompareCategory = trim(objRS6("categoryname"))%>
<% strcomparename = objRS6("name")%>
<% end if%>
<%end if%>
<%objRS6.movenext%>
<%wend%>
<%objRS6.close%>
<%set objRs6 = nothing%>
</td>
</tr>
</table>
</td>
</tr>
</table>
<% End If %>
</td>
<td>
</td>
<td valign="top" width="279">
<table width="279" border="0" cellspacing="0" cellpadding="0" bordercolor=<%=application("bgcolor")%>>
<tr>
<td align="center">
<img src="../../_images/busroutes/map<%=introuteid%>.gif" alt="" >
</td>
</tr>
</table>
</td>
</tr>
<!----------End of Stop Loacation--------------------->
<tr>
<td>
</td>
</tr>
<% if introuteid = 11 or introuteid = 101 then %>
<tr>
<td colspan="3">
<font face=<%=application("face_primary")%> size=<%=application("size_primary")%>>
Anyone may ride the SMC Commuter route, but Santa Monica College Students/Staff may ride at no cost upon presentation of a valid SMC ID card. Big Blue Bus fares apply to anyone who cannot present a valid SMC ID card.<br><br>
</font>
</td>
</tr>
<% end if %>
</table>
</td>
</tr>
<tr>
<td colspan="2" width="744" bgcolor=<%=application("bgcolor")%> height="1%" valigh="top">
<!-- #include file="../lib/footer.asp" -->
</td>
</tr>
<tr>
<td colspan="2" width="744" bgcolor="<%=Application("bgcolor")%>" height="1%">
</td>
</tr>
</table>
</body>
</html>
答案 0 :(得分:2)
是的,数据似乎来自数据库,ADODB.Command
用于向数据库发出查询并从中返回数据。在您的情况下确实发生的问题是查询不返回任何内容(我不知道您的数据库结构,但此错误是明确的)
因此,如果一切正常,您应该检查查询,如果数据存在,则应该在数据库中检查。如果所有这些都经过验证并且全部正常,则只是意味着此查询返回空,然后在显示数据之前进行检查,以查看记录集是否为空,如下所示:
If Not objRS0.EOF Then
' Do something
End If
顺便说一句,命令和记录集对象的命名很差(objRS0,objRS6),我建议你更改它们以获得更好的名称。
答案 1 :(得分:0)
问题是您根据ID查找数据库中的总线路由名称。表“tblbusroute”对于ID为1010的路由没有相应的名称,因此出错。
要解决此问题,您需要稍微更改代码。首先,现在你有这条线:
Set objRS0 = objCommand5.Execute
将此一行更改为此代码块:
Dim sBusRouteName
Set objRS0 = objCommand5.Execute
If objRS0.EOF Then
sBusRouteName = "Route " & request.querystring("routeid")
Else
sBusRouteName = objRS0("name")
End If
这会将正确的名称放入变量中,即使它不在数据库中,然后在代码中进一步更改:
<%=objRS0("name")%>
改为:
<%=sBusRouteName%>
它会显示正确的名称而不会崩溃。