database - 在 ASP 经典中添加新的 ID 和数据

标签 database asp-classic

我刚刚继承了一个用经典 ASP 编写的古老站点。短期内迫切需要更新网站(尽管他们准备在几个月内推出一个全新的网站)。

这么多年了,代码有点乱。我事先对这种语言一无所知,但我明白了要点,主要页面调用 .asp 包括等等。主要是直截了当。我的工作是更新一些时间表和 map 。当我遇到后者的问题时,我快到终点线了,在这个页面上,我得到了一个似乎是数据库错误的地方:

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

这应该显示类似于下面链接的信息(尽管显然是针对路线 10 而不是路线 7):

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

我遇到的问题是:“Route”10 行正在更改为“Rapid”10 行。现有的命名约定——或者至少是他们用来为路线提供 ID 的约定,是对常规线路/路线使用路线编号,对快速路线使用重复编号。例如,Route 7 使用 ID“7”,而 Rapid 7 使用 ID“77”。考虑到这一点,我为 route 10 的 Rapid 版本分配了 ID“1010”。这对于时间表来说效果很好(链接位于左侧栏中)。

但很明显,它因 map 而分崩离析。我从我能想到的每个角度都看过它,但我不知道是什么导致了这个问题。但由于我对 ASP 一无所知,这不足为奇。

我将“rapid 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 添加到似乎正在处理快速线路的字符串(如果这就是您所说的……对新手、 friend 和邻居要温和)。如果必须的话,请大笑,但到目前为止,这种技巧一直有效! ;)

使用上面的 Rapid & 作为工作示例的链接,谁能告诉我为什么 Rapid 10 不起作用?它是否以某种方式从数据库中获取 map 信息(我无法访问该数据库)?

任何指导将不胜感激。哦,是的,明天是我的最后期限。咕噜咕噜。

这是该页面的完整代码 - 它仅在 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">&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>
            </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>

最佳答案

是的,数据似乎来自数据库,ADODB.Command 用于向数据库发出查询并从中返回数据。你的情况确实出现的问题是查询没有返回任何东西(我不知道你的数据库结构,但这个错误很明显)

因此,如果一切正常,您应该检查查询,或者如果数据存在,则检查数据库。如果所有的都验证了并且都OK,那只是意味着这个查询返回空,然后在显示数据之前进行检查,看看记录集是否为空,就像这样:

If Not objRS0.EOF Then

' Do something

End If

顺便说一下,命令和记录集对象的命名很糟糕(objRS0、objRS6),我建议您更改它们以获得更好的名称。

关于database - 在 ASP 经典中添加新的 ID 和数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7154922/

相关文章:

sql - MySQL 递归查询

visual-studio-2010 - 尝试在 Visual Studio 2010 中运行经典 ASP 网站时出现错误

iis - 发送 Response.Status = "404 Not Found"但让 IIS 保持在同一页面上

unicode - Request.QueryString 和 Request.ServerVariables ("QUERY_STRING")不显示 UNICODE

javascript - 如何使用旧的经典 ASP 页面从 SQL 获取结果到 JavaSCript?

mysql - ASP Classic 和 MYSQL 是否可以跨多种语言设置数字格式?

mysql - 如何对我在 Wordpress 数据库中创建的自定义表进行 SQL 注入(inject)证明调用?

java - LIMIT 和 OFFSET 在 android 中不能正常工作

mysql - 如何删除数据库中MySQL表中的相关数据?

mysql - 混合数据库关系?