0

如果选择案例 7,我想显示所有这些记录,但我不知道如何在 asp classic 中打开指定的记录,可以吗?

    ELSE IF @Case = 7 BEGIN 
    SELECT TOP 5 * FROM dbo.tbl_PostalCode WHERE (PostalCode = @PostalCode)
    SELECT TOP 5 * FROM dbo.tbl_PostalCode_AutoWorkshop WHERE (PostalCode = @PostalCode)
    SELECT TOP 5 * FROM dbo.tbl_PostalCode_Expert WHERE (PostalCode = @PostalCode)
    SELECT TOP 5 * FROM dbo.tbl_PostalCode_Samsung WHERE (PostalCode = @PostalCode)
    SELECT TOP 5 * FROM dbo.tbl_PostalCode_SonyCIC WHERE (PostalCode = @PostalCode)
    SELECT TOP 5 * FROM dbo.tbl_PostalCode_Whitegoods WHERE (PostalCode = @PostalCode)
    END

这是我可以显示来自 dbo.tbl_PostalCode 的第一条记录的 html + asp

                <tr> 
                                  <td class="blackb">RecId</td>
                                    <td class="blackb">Country</td>
                                    <td class="blackb">PostalCode</td>
                                    <td class="blackb">Town</td>
                                    <td class="blackb">Lat</td>
                                    <td class="blackb">Lng</td>
                </tr>


                                                    <%
                                If Not RSOrder.EOF then
                                    Do Until RSOrder.EOF
                                %>
                                <tr>    
                                    <td><%=RSOrder("Rec_ID")%> </td>
                                        <td><%=RSOrder("Country")%></td>
                                        <td><%=RSOrder("PostalCode")%>  </td>
                                        <td><%=RSOrder("Town")%> </td>
                                        <td><%=RSOrder("Lat")%></td>
                                        <td><%=RSOrder("Lng")%></td>
                                </tr>


                                    <% 
                                        RSOrder.MoveNext
                                    Loop
                                Else%>




                                <%End If %>
                                <%End if%> 
4

1 回答 1

2

您最好的办法是让您的 SQL 返回一个结果集而不是 6 个,进行如下更改:

ELSE IF @Case = 7 
BEGIN 
    SELECT TOP 5 * FROM dbo.tbl_PostalCode WHERE (PostalCode = @PostalCode)
    UNION
    SELECT TOP 5 * FROM dbo.tbl_PostalCode_AutoWorkshop WHERE (PostalCode = @PostalCode)
    UNION
    SELECT TOP 5 * FROM dbo.tbl_PostalCode_Expert WHERE (PostalCode = @PostalCode)
    UNION
    SELECT TOP 5 * FROM dbo.tbl_PostalCode_Samsung WHERE (PostalCode = @PostalCode)
    UNION
    SELECT TOP 5 * FROM dbo.tbl_PostalCode_SonyCIC WHERE (PostalCode = @PostalCode)
    UNION
    SELECT TOP 5 * FROM dbo.tbl_PostalCode_Whitegoods WHERE (PostalCode = @PostalCode)
END

这样,当您循环遍历记录集时 - 单个循环将产生所有结果

作为替代方案,如果您需要保留返回多个结果的当前 SQL,请使用 Recodset 的NextRecordset方法,它允许您创建一个循环通过返回结果的外循环(内循环仍然是您当前循环通过单个记录的循环)

在你的情况下,它会像

Do Until RSOrder is Nothing

   Do Until RSOrder.EOF

      'Using function from http://www.devx.com/tips/Tip/42275 to see if specific field exists
      If FieldExistsInRS(RSOrder, "MyColumn")
         'do something specific for this result
      End If

      RSOrder.MoveNext
   Loop

   'Get result from the next SELECT
   Set RSOrder = RSOrder.NextRecordset 

Loop
于 2013-08-15T13:29:16.843 回答