| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 515 人关注过本帖
标题:好心人帮忙看看这代码该怎么优化?
只看楼主 加入收藏
rz250
Rank: 1
等 级:禁止访问
帖 子:4
专家分:0
注 册:2013-11-17
结帖率:0
收藏
 问题点数:0 回复次数:1 
好心人帮忙看看这代码该怎么优化?
下面是某个网站的主页的[部份代码](还有很多类似的分类查询),觉得打开好慢,估计是因为执行太多的查询语句导致的。  现在使用 ASP + Access,准备把 Access 换成 SQLServer 2005。数据不够3千条记录。
1.主页绝大多数是查询同一个表,只是条件不同,能否把多条查询语句合在一起,返回多个记录集,效率是否会大大的提高呢?
2.看到网上有存存储过程可以返回多个记录集的,不知使用ASP代码是否可以返回多个记录集。
3.针对现在的代码,给点优化性能的建议。  
 
<div class="left_tit"><span><a href="class-6.html" title="编程语言" target="_blank">更多</a></span><div style="float:left"><strong>编程语言</strong></div>
            <div id="scrollDiv" class="my_croll">
                <ul>
                    <%Set rs=Server.CreateObject("ADODB.RecordSet")
                    sql="Select Top 5 id,title From news Where bigclass=6 And hot='True' Order By id Desc"
                    rs.Open sql,conn,1,1
                    If rs.Eof Or rs.Bof Then
                      Response.Write("")
                    Else
                    i=0
                    Do While Not rs.Eof%>
                    <li><a href="<%=rs("id")%>.html" title="<%=rs("title")%>" target="_blank"><%=leftT(rs("title"),24)%></a></li>
                    <%rs.MoveNext
                    Loop
                    End If
                    rs.Close
                    Set rs=Nothing%>
                </ul>
            </div>
        </div>
        <div class="left_list">
            <ul class="l_tj">
                <%Set rs=Server.CreateObject("ADODB.RecordSet")
                sql="Select Top 1 id,title,[desc],pic From news Where bigclass=6 And pic is not Null And flag='False' And flash = 'False' Order By id Desc"
                rs.Open sql,conn,1,1
                If rs.Eof Or rs.Bof Then
                  Response.Write("<li>此暂时没有信息!</li>")
                Else%>
                <li class="l_pic"><a href="<%=rs("id")%>.html" target="_blank" title="<%=rs("title")%>"><img src="<%=rs("pic")%>" width="118" height="80" border="0"></a></li>
                <li class="l_text"><%=leftT(RemoveHTML(rs("desc")),70)%>[<a href="<%=rs("id")%>.html" target="_blank">详细</a>]</li>
                <%End If
                  rs.Close
                  Set rs=Nothing%>
            </ul>
            <ul class="l_list">
                <%Set rs=Server.CreateObject("ADODB.RecordSet")
                sql="Select Top 11 id,title From news Where bigclass=6 And pic is Null And flag='False' And flash = 'False' Order By id Desc"
                rs.Open sql,conn,1,1
                If rs.Eof Or rs.Bof Then
                  Response.Write("<li>此暂时没有信息!</li>")
                Else
                i=0
                Do While Not rs.Eof%>
                <li>· <a href="<%=rs("id")%>.html" title="<%=rs("title")%>" target="_blank"><%=rs("title")%></a></li>
                <%rs.MoveNext
                Loop
                End If
                rs.Close
                Set rs=Nothing%>
            </ul>
      </div>
        <div class="left_tit"><span><a href="class-9.html" title="网络技术" target="_blank">更多</a></span><strong>网络技术</strong><%Set rs=Server.CreateObject("ADODB.RecordSet")
            sql="Select Top 1 id,title From news Where bigclass=9 And hot='True' Order By id Desc"
            rs.Open sql,conn,1,1
            If rs.Eof Or rs.Bof Then
              Response.Write("")
            Else%>&nbsp;&nbsp;<label class="my_title"><a href="<%=rs("id")%>.html" target="_blank" title="<%=rs("title")%>"><%=leftT(rs("title"),24)%></a></label><%End If
            rs.Close
            Set rs=Nothing%>
        </div>
        <div class="left_list">
            <ul class="l_tj">
                <%Set rs=Server.CreateObject("ADODB.RecordSet")
                sql="Select Top 1 id,title,[desc],pic From news Where bigclass=9 And pic is not Null And flag='False' And flash = 'False' Order By id Desc"
                rs.Open sql,conn,1,1
                If rs.Eof Or rs.Bof Then
                  Response.Write("<li>此暂时没有信息!</li>")
                Else%>
                <li class="l_pic"><a href="<%=rs("id")%>.html" target="_blank" title="<%=rs("title")%>"><img src="<%=rs("pic")%>" width="118" height="80" border="0"></a></li>
                <li class="l_text"><%=leftT(RemoveHTML(rs("desc")),70)%>[<a href="<%=rs("id")%>.html" target="_blank">详细</a>]</li>
                <%End If
                rs.Close
                Set rs=Nothing%>
            </ul>
            <ul class="l_list">
                <%Set rs=Server.CreateObject("ADODB.RecordSet")
                sql="Select Top 8 id,title From news Where bigclass=9 And pic is Null And flag='False' And flash = 'False' Order By id Desc"
                rs.Open sql,conn,1,1
                If rs.Eof Or rs.Bof Then
                  Response.Write("<li>此暂时没有信息!</li>")
                Else
                i=0
                Do While Not rs.Eof%>
                <li>· <a href="<%=rs("id")%>.html" title="<%=rs("title")%>" target="_blank"><%=rs("title")%></a></li>
                <%rs.MoveNext
                Loop
                End If
                rs.Close
                Set rs=Nothing%>
            </ul>
      </div>
搜索更多相关主题的帖子: 编程语言 title 记录 网上 
2013-11-19 11:52
ysf0181
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:55
帖 子:914
专家分:2385
注 册:2006-10-4
收藏
得分:0 
sql 缓存打开查询数据库。

百度吧。怎么写缓存代码。

ASP讨论QQ群:251346273
2013-11-19 15:56
快速回复:好心人帮忙看看这代码该怎么优化?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.047432 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved