开发者

adding a new ID and data in ASP classic

I've just inherited an ancient site written in classic ASP. There is an immediate need to update the site in the short term (although they are preparing to launch an entirely new site in a few months).

The code is a bit of a mess after all these years. I have no prior knowledge of this language, but I get the gist, with main pages calling in .asp includes and all that. Mostly straightforward. My job is to update some schedules and maps. I was almost to the finish line when I ran into a problem with the latter, on this page, where I get what appears to be a database error:

http://test.bigbluebus.com/busroutes/map/index.asp?routeid=1010

This should display information similar to the link below (though obviously for route 10 rather than route 7):

http://test.bigbluebus.com/busroutes/map/index.asp?routeid=77

The issue I'm having is this: "Route" 10 line is changing to "Rapid" 10 line. The existing naming convention - or at least the convention they use to provide IDs for the routes, is to use the route number for a regular line/route, and to use a repeated number for a rapid route. For example, Route 7 used the ID "7" while the Rapid 7 uses the ID "77". With that in mind I assigned the Rapid version of route 10 with the ID "1010." This worked beautifully for the schedules (links located in the left hand column).

But clearly it's falling apart for the maps. I've looked at it from every angle I can think of and I don't know what could be causing this problem. But since I know nothing of ASP, this is hardly surprising.

I linked the "rapid 10" left column link to routeid 1010, and on line 151 of the index.asp it links to I simply changed:

<% if introuteid <> 33 AND  introuteid <> 77 AND introuteid <> 111 then %>

to

<% if introuteid <> 33 AND  introuteid <> 77 AND introuteid <> 111 AND introuteid <> 1010 then %>

Simply adding 1010 to the string (if that's what you even call it... Be gentle with the newbie, friends and neighbors) that appears to be dealing with rapid lines. Laugh if you must, but this technique has worked so far! ;)

Using the above link to Rapid & as a working example, can anyone tell me why Rapid 10 isn't working? Is it somehow taking this map info from a database (to which I would have no access)?

Any guidance would be greatly appreciated. Oh yeah, and tomorrow's my deadline. Gulp.

Here's the full code of the page - it only breaks on 1010 (rapid 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">&nbsp;

        </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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=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>&nbsp;|&nbsp;Map&nbsp;|&nbsp;<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>&nbsp;|&nbsp;<a href="../../busroutes/schedule.asp?bus_route=<%=introuteid%>&dayofweek=saturday">Saturday</a>&nbsp;|&nbsp;<a href="../../busroutes/schedule.asp?bus_route=<%=introuteid%>&dayofweek=sunday">Sunday/Holidays</a></center>
                </font>
                </td>
            </tr>
            </table>
            <开发者_如何学JAVA/td>
        </tr>
        </table>
        </td>
    </tr>
    <tr>            
        <td colspan="3">&nbsp;

        </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>&nbsp;

        </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>&nbsp;

        </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%">&nbsp;

    </td>
</tr>
</table>
</body>
</html>


Yes the data seems to come from the database, ADODB.Command is used to issue a query to the database and to return data from it. The problem that does occur in your case is that the query does not return anything (I don't know your database structure, but this error is clear)

So you should check in the query if everything is ok or in the database if the data exists. If all that is verified and all Ok, it just means that this query return empty and then make a check before displaying data, to see if the recordset is empty like this :

If Not objRS0.EOF Then

' Do something

End If

By the way, commands and recordsets objects are poorly named (objRS0, objRS6), I suggest you change them for better names.


The problem is that you look for the name of the bus route in the database, according to the ID. The table "tblbusroute" has no corresponding name for route with ID 1010, hence the error.

To fix this, you need to slightly change the code. First, right now you have this line:

Set objRS0 = objCommand5.Execute

Change this one line to become this code block instead:

Dim sBusRouteName
Set objRS0 = objCommand5.Execute
If objRS0.EOF Then
    sBusRouteName = "Route " & request.querystring("routeid")
Else  
    sBusRouteName = objRS0("name")
End If

This will put proper name into variable, even when it's not in database, then further in the code, change this:

<%=objRS0("name")%>

To be this instead:

<%=sBusRouteName%>

And it will show the proper name without crashing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜